Last active
May 17, 2020 09:54
-
-
Save AndrewBestbier/2ef501e34ff165f7e514bcb4bd39c1b7 to your computer and use it in GitHub Desktop.
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
import * as cdk from '@aws-cdk/core'; | |
import * as s3 from '@aws-cdk/aws-s3'; | |
import * as iam from '@aws-cdk/aws-iam'; | |
export class InfrastructureStack extends cdk.Stack { | |
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
const bucket = new s3.Bucket(this, 'WebsiteBucket', { | |
bucketName: 'andrew-bestbier-cdk-blog', | |
websiteIndexDocument: 'index.html', // 1 | |
blockPublicAccess: new s3.BlockPublicAccess({ restrictPublicBuckets: false }) // 2 | |
}); | |
// 3 | |
const bucketPolicy = new iam.PolicyStatement({ | |
actions: ['s3:GetObject'], | |
resources: [ | |
`${bucket.bucketArn}/*` | |
], | |
principals: [new iam.Anyone()], | |
}) | |
bucket.addToResourcePolicy(bucketPolicy); // 4 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment