Skip to content

Commit 21f65e0

Browse files
committed
refactor: s3 Stack lifecycle
1 parent b782e8f commit 21f65e0

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed

bin/decidim-cfj-cdk.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {ElasticacheStack} from "../lib/elasticache-stack";
99
import {DecidimStack} from "../lib/decidim-stack";
1010
import {CloudFrontStack} from "../lib/cloudfront";
1111
import {Tags} from 'aws-cdk-lib';
12-
import {S3PolicyStack} from "../lib/s3-policy";
1312

1413
const app = new cdk.App();
1514

@@ -99,13 +98,6 @@ const distribution = new CloudFrontStack(app, `${stage}${serviceName}CloudFrontS
9998
distribution.addDependency(service)
10099
distribution.addDependency(s3Stack)
101100

102-
new S3PolicyStack(app, `${stage}${serviceName}S3PolicyStack`, {
103-
stage,
104-
serviceName,
105-
env,
106-
bucket: s3Stack.bucket
107-
})
108-
109101
Tags.of(app).add('Project', 'Decidim')
110102
Tags.of(app).add('Repository', 'decidim-cfj-cdk')
111103
Tags.of(app).add('GovernmentName', 'code4japan')

lib/s3-policy.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

lib/s3-stack.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {aws_s3, RemovalPolicy, Stack} from "aws-cdk-lib";
1+
import {aws_iam as iam, aws_s3, aws_ssm as ssm, RemovalPolicy, Stack} from "aws-cdk-lib";
22
import {Construct} from "constructs";
33
import {BaseStackProps} from "./props";
44
import {HttpMethods} from "aws-cdk-lib/aws-s3";
@@ -34,5 +34,18 @@ export class S3Stack extends Stack {
3434
}
3535
]
3636
});
37+
38+
const distArn = ssm.StringParameter.valueForStringParameter(
39+
this, `/decidim-cfj/${props.stage}/CLOUDFRONT_DISTRIBUTION_ARN`
40+
);
41+
42+
this.bucket.addToResourcePolicy(new iam.PolicyStatement({
43+
sid: "AllowCloudFrontOACRead",
44+
effect: iam.Effect.ALLOW,
45+
principals: [ new iam.ServicePrincipal("cloudfront.amazonaws.com") ],
46+
actions: ["s3:GetObject"],
47+
resources: [ `${this.bucket.bucketArn}/*` ],
48+
conditions: { StringEquals: { "AWS:SourceArn": distArn } },
49+
}));
3750
}
3851
}

0 commit comments

Comments
 (0)