Created
May 31, 2020 23:36
-
-
Save what-name/c2292fa35e6710bbe0185c9de320eb11 to your computer and use it in GitHub Desktop.
S3 Static Hosting + CloudFormation + CORS + YAML
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
--- | |
Parameters: | |
S3BucketName: | |
Description: "The name of the S3 bucket that will store the website files" | |
Type: String | |
Resources: | |
WebsiteBucket: | |
Type: AWS::S3::Bucket | |
Properties: | |
BucketName: | |
Ref: S3BucketName | |
AccessControl: PublicRead | |
WebsiteConfiguration: | |
IndexDocument: index.html | |
# ErrorDocument: error.html | |
CorsConfiguration: | |
# THIS was the part where my brain melted | |
CorsRules: | |
- | |
AllowedMethods: | |
- GET | |
AllowedOrigins: | |
- "*" | |
AllowedHeaders: | |
- "*" | |
WebsiteBucketBucketPolicy: | |
Type: AWS::S3::BucketPolicy | |
Properties: | |
PolicyDocument: | |
Id: PublicAccessPolicy | |
Version: 2012-10-17 | |
Statement: | |
- Sid: PublicReadForGetBucketObjects | |
Effect: Allow | |
Principal: '*' | |
Action: 's3:GetObject' | |
Resource: !Join | |
- '' | |
- - 'arn:aws:s3:::' | |
- !Ref WebsiteBucket | |
- /* | |
Bucket: !Ref WebsiteBucket | |
Outputs: | |
WebsiteURL: | |
Value: !GetAtt | |
- WebsiteBucket | |
- WebsiteURL | |
Description: URL for website hosted on S3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment