-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add CORS Property to S3 Bucket for configuring bucket cross-origin access rules.
- v2.173.2
- v2.173.1
- v2.173.0
- v2.172.0
- v2.171.1
- v2.171.0
- v2.170.0
- v2.169.0
- v2.168.0
- v2.167.2
- v2.167.1
- v2.167.0
- v2.166.0
- v2.165.0
- v2.164.1
- v2.164.0
- v2.163.1
- v2.163.0
- v2.162.1
- v2.162.0
- v2.161.1
- v2.161.0
- v2.160.0
- v2.159.1
- v2.159.0
- v2.158.0
- v2.157.0
- v2.156.0
- v2.155.0
- v2.154.1
- v2.154.0
- v2.153.0
- v2.152.0
- v2.151.1
- v2.151.0
- v2.150.0
- v2.149.0
- v2.148.1
- v2.148.0
- v2.147.3
- v2.147.2
- v2.147.1
- v2.147.0
- v2.146.0
- v2.145.0
- v2.144.0
- v2.143.1
- v2.143.0
- v2.142.1
- v2.142.0
- v2.141.0
- v2.140.0
- v2.139.1
- v2.139.0
- v2.138.0
- v2.137.0
- v2.136.1
- v2.136.0
- v2.135.0
- v2.134.0
- v2.133.0
- v2.132.1
- v2.132.0
- v2.131.0
- v2.130.0
- v2.129.0
- v2.128.0
- v2.127.0
- v2.126.0
- v2.125.0
- v2.124.0
- v2.123.0
- v2.122.0
- v2.121.1
- v2.121.0
- v2.120.0
- v2.119.0
- v2.118.0
- v2.117.0
- v2.116.1
- v2.116.0
- v2.115.0
- v2.114.1
- v2.114.0
- v2.113.0
- v2.112.0
- v2.111.0
- v2.110.1
- v2.110.0
- v2.109.0
- v2.108.1
- v2.108.0
- v2.107.0
- v2.106.1
- v2.106.0
- v2.105.0
- v2.104.0
- v2.103.1
- v2.103.0
- v2.102.1
- v2.102.0
- v2.101.1
- v2.101.0
- v2.100.0
- v2.99.1
- v2.99.0
- v2.98.0
- v2.97.1
- v2.97.0
- v2.96.2
- v2.96.1
- v2.96.0
- v2.95.1
- v2.95.0
- v2.94.0
- v2.93.0
- v2.92.0
- v2.91.0
- v2.90.0
- v2.89.0
- v2.88.0
- v2.87.0
- v2.86.0
- v2.85.0
- v2.84.0
- v2.83.1
- v2.83.0
- v2.82.0
- v2.81.0
- v2.80.0
- v2.79.1
- v2.79.0
- v2.78.0
- v2.77.0
- v2.76.0
- v2.75.1
- v2.75.0
- v2.74.0
- v2.73.0
- v2.72.1
- v2.72.0
- v2.71.0
- v2.70.0
- v2.69.0
- v2.68.0
- v2.67.0
- v2.66.1
- v2.66.0
- v2.65.0
- v2.64.0
- v2.63.2
- v2.63.1
- v2.63.0
- v2.62.2
- v2.62.1
- v2.62.0
- v2.61.1
- v2.61.0
- v2.60.0
- v2.59.0
- v2.58.1
- v2.58.0
- v2.57.0
- v2.56.1
- v2.56.0
- v2.55.1
- v2.55.0
- v2.54.0
- v2.53.0
- v2.52.1
- v2.52.0
- v2.51.1
- v2.51.0
- v2.50.0
- v2.49.1
- v2.49.0
- v2.48.0
- v2.47.0
- v2.46.0
- v2.45.0
- v2.44.0
- v2.43.1
- v2.43.0
- v2.42.1
- v2.42.0
- v2.41.0
- v2.40.0
- v2.39.1
- v2.39.0
- v2.38.1
- v2.38.0
- v2.37.1
- v2.37.0
- v2.36.0
- v2.35.0
- v2.34.2
- v2.34.1
- v2.34.0
- v2.33.0
- v2.32.1
- v2.32.0
- v2.31.2
- v2.31.1
- v2.31.0
- v2.30.0
- v2.29.1
- v2.29.0
- v2.28.1
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.0
- v2.24.1
- v2.24.0
- v2.23.0
- v2.22.0
- v2.21.1
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v2.0.0-rc.33
- v2.0.0-rc.32
- v2.0.0-rc.31
- v2.0.0-rc.30
- v2.0.0-rc.29
- v2.0.0-rc.28
- v2.0.0-rc.27
- v2.0.0-rc.26
- v2.0.0-rc.25
- v2.0.0-rc.24
- v2.0.0-rc.23
- v2.0.0-rc.22
- v2.0.0-rc.21
- v2.0.0-rc.20
- v2.0.0-rc.19
- v2.0.0-rc.18
- v2.0.0-rc.17
- v2.0.0-rc.16
- v2.0.0-rc.15
- v2.0.0-rc.14
- v2.0.0-rc.13
- v2.0.0-rc.12
- v2.0.0-rc.11
- v2.0.0-rc.10
- v2.0.0-rc.9
- v2.0.0-rc.8
- v2.0.0-rc.7
- v2.0.0-rc.6
- v2.0.0-rc.5
- v2.0.0-rc.4
- v2.0.0-rc.3
- v2.0.0-rc.1
- v2.0.0-alpha.14
- v2.0.0-alpha.13
- v2.0.0-alpha.12
- v2.0.0-alpha.11
- v2.0.0-alpha.10
- v2.0.0-alpha.6
- v2.0.0-alpha.5
- v2.0.0-alpha.4
- v2.0.0-alpha.3
- v2.0.0-alpha.2
- v2.0.0-alpha.1
- v2.0.0-alpha.0
- v1.204.0
- v1.203.0
- v1.202.0
- v1.201.0
- v1.200.0
- v1.199.0
- v1.198.1
- v1.198.0
- v1.197.0
- v1.196.0
- v1.195.0
- v1.194.0
- v1.193.0
- v1.192.0
- v1.191.0
- v1.190.0
- v1.189.0
- v1.188.0
- v1.187.0
- v1.186.1
- v1.186.0
- v1.185.0
- v1.184.1
- v1.184.0
- v1.183.0
- v1.182.0
- v1.181.1
- v1.181.0
- v1.180.0
- v1.179.0
- v1.178.0
- v1.177.0
- v1.176.0
- v1.175.0
- v1.174.0
- v1.173.0
- v1.172.0
- v1.171.0
- v1.170.1
- v1.170.0
- v1.169.0
- v1.168.0
- v1.167.0
- v1.166.1
- v1.165.0
- v1.164.0
- v1.163.2
- v1.163.1
- v1.163.0
- v1.162.0
- v1.161.0
- v1.160.0
- v1.159.0
- v1.158.0
- v1.157.0
- v1.156.1
- v1.156.0
- v1.155.0
- v1.154.0
- v1.153.1
- v1.153.0
- v1.152.0
- v1.151.0
- v1.150.0
- v1.149.0
- v1.148.0
- v1.147.0
- v1.146.0
- v1.145.0
- v1.144.0
- v1.143.0
- v1.142.0
- v1.141.0
- v1.140.0
- v1.139.0
- v1.138.2
- v1.138.1
- v1.138.0
- v1.137.0
- v1.136.0
- v1.135.0
- v1.134.0
- v1.133.0
- v1.132.0
- v1.131.0
- v1.130.0
- v1.129.0
- v1.128.0
- v1.127.0
- v1.126.0
- v1.125.0
- v1.124.0
- v1.123.0
- v1.122.0
- v1.121.0
- v1.120.0
- v1.119.0
- v1.118.0
- v1.117.0
- v1.116.0
- v1.115.0
- v1.114.0
- v1.113.0
- v1.112.0
- v1.111.0
- v1.110.1
- v1.110.0
- v1.109.0
- v1.108.1
- v1.108.0
- v1.107.0
- v1.106.1
- v1.106.0
- v1.105.0
- v1.104.0
- v1.103.0
- v1.102.0
- v1.101.0
- v1.100.0
- v1.99.0
- v1.98.0
- v1.97.0
- v1.96.0
- v1.95.2
- v1.95.1
- v1.95.0
- v1.94.1
- v1.94.0
- v1.93.0
- v1.92.0
- v1.91.0
- v1.90.1
- v1.90.0
- v1.89.0
- v1.88.0
- v1.87.1
- v1.87.0
- v1.86.0
- v1.85.0
- v1.84.0
- v1.83.0
- v1.82.0
- v1.81.0
- v1.80.0
- v1.79.0
- v1.78.0
- v1.77.0
- v1.76.0
- v1.75.0
- v1.74.0
- v1.73.0
- v1.72.0
- v1.71.0
- v1.70.0
- v1.69.0
- v1.68.0
- v1.67.0
- v1.66.0
- v1.65.0
- v1.64.1
- v1.64.0
- v1.63.0
- v1.62.0
- v1.61.1
- v1.61.0
- v1.60.0
- v1.59.0
- v1.58.0
- v1.57.0
- v1.56.0
- v1.55.0
- v1.54.0
- v1.53.0
- v1.52.0
- v1.51.0
- v1.50.0
- v1.49.1
- v1.49.0
- v1.48.0
- v1.47.1
- v1.47.0
- v1.46.0
- v1.45.0
- v1.44.0
- v1.43.0
- v1.42.1
- v1.42.0
- v1.41.0
- v1.40.0
- v1.39.0
- v1.38.0
- v1.37.0
- v1.36.1
- v1.36.0
- v1.35.0
- v1.34.1
- v1.34.0
- v1.33.1
- v1.33.0
- v1.32.2
- v1.32.1
- v1.32.0
- v1.31.0
- v1.30.0
- v1.29.0
- v1.28.0
- v1.27.0
- v1.26.0
- v1.25.0
- v1.24.0
- v1.23.0
- v1.22.0
- v1.21.1
- v1.21.0
- v1.20.0
- v1.19.0
- v1.18.0
- v1.17.1
- v1.17.0
- v1.16.3
- v1.16.2
- v1.16.1
- v1.16.0
- v1.15.0
- v1.14.0
- v1.13.1
- v1.13.0
- v1.12.0
- v1.11.0
- v1.10.1
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- v0.39.0
- v0.38.0
- v0.37.0
- v0.36.2
- v0.36.1
- v0.36.0
- v0.35.0
Showing
2 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { expect, haveResource } from '@aws-cdk/assert'; | ||
import { Stack } from '@aws-cdk/cdk'; | ||
import { Test } from 'nodeunit'; | ||
import { Bucket, HttpMethods } from '../lib'; | ||
|
||
export = { | ||
'Can use addCors() to add a CORS configuration'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
const bucket = new Bucket(stack, 'Bucket'); | ||
bucket.addCorsRule({ | ||
allowedMethods: [HttpMethods.GET, HttpMethods.HEAD], | ||
allowedOrigins: ["https://example.com"] | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::S3::Bucket', { | ||
CorsConfiguration: { | ||
CorsRules: [{ | ||
AllowedMethods: ["GET", "HEAD"], | ||
AllowedOrigins: ["https://example.com"] | ||
}] | ||
} | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'Bucket with multiple cors configurations'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
|
||
// WHEN | ||
new Bucket(stack, 'Bucket', { | ||
cors: [ | ||
{ | ||
allowedHeaders: [ | ||
"*" | ||
], | ||
allowedMethods: [ | ||
HttpMethods.GET | ||
], | ||
allowedOrigins: [ | ||
"*" | ||
], | ||
exposedHeaders: [ | ||
"Date" | ||
], | ||
id: "myCORSRuleId1", | ||
maxAge: 3600 | ||
}, | ||
{ | ||
allowedHeaders: [ | ||
"x-amz-*" | ||
], | ||
allowedMethods: [ | ||
HttpMethods.DELETE | ||
], | ||
allowedOrigins: [ | ||
"http://www.example1.com", | ||
"http://www.example2.com" | ||
], | ||
exposedHeaders: [ | ||
"Connection", | ||
"Server", | ||
"Date" | ||
], | ||
id: "myCORSRuleId2", | ||
maxAge: 1800 | ||
} | ||
] | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResource('AWS::S3::Bucket', { | ||
CorsConfiguration: { | ||
CorsRules: [ | ||
{ | ||
AllowedHeaders: [ | ||
"*" | ||
], | ||
AllowedMethods: [ | ||
"GET" | ||
], | ||
AllowedOrigins: [ | ||
"*" | ||
], | ||
ExposedHeaders: [ | ||
"Date" | ||
], | ||
Id: "myCORSRuleId1", | ||
MaxAge: 3600 | ||
}, | ||
{ | ||
AllowedHeaders: [ | ||
"x-amz-*" | ||
], | ||
AllowedMethods: [ | ||
"DELETE" | ||
], | ||
AllowedOrigins: [ | ||
"http://www.example1.com", | ||
"http://www.example2.com" | ||
], | ||
ExposedHeaders: [ | ||
"Connection", | ||
"Server", | ||
"Date" | ||
], | ||
Id: "myCORSRuleId2", | ||
MaxAge: 1800 | ||
} | ||
] | ||
} | ||
})); | ||
|
||
test.done(); | ||
}, | ||
}; |