MCPcopy Create free account
hub / github.com/aws-samples/aws-dev-hour-backend / AwsdevhourStack

Class AwsdevhourStack

lib/awsdevhour-stack.ts:21–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19const websiteBucketName = "cdk-rekn-publicbucket"
20
21export class AwsdevhourStack extends cdk.Stack {
22 constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
23 super(scope, id, props);
24
25 // =====================================================================================
26 // Image Bucket
27 // =====================================================================================
28 const imageBucket = new s3.Bucket(this, imageBucketName, {
29 removalPolicy: cdk.RemovalPolicy.DESTROY
30 });
31 new cdk.CfnOutput(this, 'imageBucket', { value: imageBucket.bucketName });
32 const imageBucketArn = imageBucket.bucketArn;
33 imageBucket.addCorsRule({
34 allowedMethods: [HttpMethods.GET, HttpMethods.PUT],
35 allowedOrigins: ["*"],
36 allowedHeaders: ["*"],
37 maxAge: 3000
38 });
39
40 // =====================================================================================
41 // Thumbnail Bucket
42 // =====================================================================================
43 const resizedBucket = new s3.Bucket(this, resizedBucketName, {
44 removalPolicy: cdk.RemovalPolicy.DESTROY
45 });
46 new cdk.CfnOutput(this, 'resizedBucket', {value: resizedBucket.bucketName});
47 const resizedBucketArn = resizedBucket.bucketArn;
48 resizedBucket.addCorsRule({
49 allowedMethods: [HttpMethods.GET, HttpMethods.PUT],
50 allowedOrigins: ["*"],
51 allowedHeaders: ["*"],
52 maxAge: 3000
53 });
54
55 // =====================================================================================
56 // Construct to create our Amazon S3 Bucket to host our website
57 // =====================================================================================
58 const webBucket = new s3.Bucket(this, websiteBucketName, {
59 websiteIndexDocument: 'index.html',
60 websiteErrorDocument: 'index.html',
61 removalPolicy: cdk.RemovalPolicy.DESTROY
62 // publicReadAccess: true,
63 });
64
65 webBucket.addToResourcePolicy(new iam.PolicyStatement({
66 actions: ['s3:GetObject'],
67 resources: [webBucket.arnForObjects('*')],
68 principals: [new iam.AnyPrincipal()],
69 conditions: {
70 'IpAddress': {
71 'aws:SourceIp': [
72 '*.*.*.*/*' // Please change it to your IP address or from your allowed list
73 ]
74 }
75 }
76
77 }))
78 new cdk.CfnOutput(this, 'bucketURL', { value: webBucket.bucketWebsiteDomainName });

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected