Skip to content

Commit bb113fe

Browse files
authored
Merge pull request #74 from codeforjapan/fix/#50
Fix/#50
2 parents 63286eb + c249614 commit bb113fe

File tree

10 files changed

+32
-20
lines changed

10 files changed

+32
-20
lines changed

bin/decidim-cfj-cdk.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const cloudfrontEnv = {
3535
new S3Stack(app, `${ stage }${ serviceName }S3Stack`, {
3636
stage,
3737
env,
38-
serviceName
38+
serviceName,
39+
bucketName: config.s3Bucket
3940
})
4041

4142
const network = new NetworkStack(app, `${ stage }${ serviceName }NetworkStack`, {
@@ -81,7 +82,8 @@ const service = new DecidimStack(app, `${ stage }${ serviceName }Stack`, {
8182
securityGroupForAlb: network.sgForAlb,
8283
domain: config.domain,
8384
rds: rds.rds.dbInstanceEndpointAddress,
84-
cache: elastiCache.redis.attrPrimaryEndPointAddress
85+
cache: elastiCache.redis.attrPrimaryEndPointAddress,
86+
bucketName: config.s3Bucket,
8587
})
8688
service.addDependency(network)
8789

config/dev.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"rds": {
33
"snapshot": true,
4-
"snapshotIdentifier": "decidim-master-2025-06-24",
4+
"snapshotIdentifier": "decidim-master-2025-08-11",
55
"instanceType": "t3.micro",
66
"deletionProtection": false,
77
"allocatedStorage": 20,
@@ -15,6 +15,8 @@
1515
"region": "ap-northeast-1"
1616
},
1717

18+
"s3Bucket": "dev-v300-decidim",
19+
1820
"cacheNodeType": "cache.t3.medium",
1921
"engineVersion": "6.x",
2022
"numCacheNodes": 1,

config/prd-v0292.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"region": "ap-northeast-1"
1616
},
1717

18+
"s3Bucket": "prd-v0292-decidim",
19+
1820
"cacheNodeType": "cache.t3.medium",
1921
"engineVersion": "6.x",
2022
"numCacheNodes": 3,

config/staging.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"region": "ap-northeast-1"
1616
},
1717

18+
"s3Bucket": "staging-decidim",
19+
1820
"cacheNodeType": "cache.t2.micro",
1921
"engineVersion": "6.x",
2022
"numCacheNodes": 1,

lib/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export interface Config {
4747
region: string;
4848
};
4949

50+
s3Bucket: string
51+
5052
// rds
5153
rds: RdsConfig
5254

lib/decidim-stack.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ApplicationTargetGroup, ListenerCertificate } from "aws-cdk-lib/aws-ela
2121
import { Repository } from 'aws-cdk-lib/aws-ecr';
2222
import { DockerImageAsset, Platform } from 'aws-cdk-lib/aws-ecr-assets';
2323
import { DockerImageName, ECRDeployment } from 'cdk-ecr-deployment';
24-
import { capacityProviderStrategy } from "../lib/config";
24+
import { capacityProviderStrategy } from "./config";
2525
import path = require('path');
2626
import { EcsTask } from "aws-cdk-lib/aws-events-targets";
2727
import { Rule, Schedule } from 'aws-cdk-lib/aws-events';
@@ -44,7 +44,8 @@ export interface DecidimStackProps extends BaseStackProps {
4444
certificates: string[]
4545
fargateCapacityProvider: capacityProviderStrategy
4646
fargateSpotCapacityProvider: capacityProviderStrategy
47-
}
47+
},
48+
bucketName: string,
4849
}
4950

5051
export class DecidimStack extends cdk.Stack {
@@ -60,7 +61,7 @@ export class DecidimStack extends cdk.Stack {
6061

6162
const ECSExecPolicyStatement = new aws_iam.PolicyStatement({
6263
sid: 'allowS3access',
63-
resources: [`arn:aws:s3:::${ props.stage }-${ props.serviceName }-bucket*`],
64+
resources: [`arn:aws:s3:::${ props.bucketName }*`],
6465
actions: ['s3:*'],
6566
});
6667

@@ -128,7 +129,7 @@ export class DecidimStack extends cdk.Stack {
128129
SMTP_USERNAME: ssm.StringParameter.valueForTypedStringParameterV2(this, `/decidim-cfj/${ props.stage }/SMTP_USERNAME`),
129130
SMTP_PASSWORD: ssm.StringParameter.valueForTypedStringParameterV2(this, `/decidim-cfj/${ props.stage }/SMTP_PASSWORD`),
130131
SMTP_DOMAIN: props.ecs.smtpDomain,
131-
AWS_BUCKET_NAME: `${ props.stage }-${ props.serviceName }-bucket`,
132+
AWS_BUCKET_NAME: `${ props.bucketName }-bucket`,
132133
DECIDIM_COMMENTS_LIMIT: "30",
133134
SLACK_API_TOKEN: ssm.StringParameter.valueForTypedStringParameterV2(this, `/decidim-cfj/${ props.stage }/SLACK_API_TOKEN`),
134135
AWS_XRAY_TRACING_NAME: `decidim-app${ props.stage }`,
@@ -314,7 +315,7 @@ export class DecidimStack extends cdk.Stack {
314315

315316
// ALB Log
316317
const logBucket = new aws_s3.Bucket(this, `${ props.stage }AlbLogBucket`, {
317-
bucketName: `${ props.stage }-${ props.serviceName }-alb-logs`,
318+
bucketName: `${ props.bucketName }-alb-logs`,
318319
removalPolicy: RemovalPolicy.DESTROY,
319320
autoDeleteObjects: true,
320321
})

lib/s3-stack.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import { Construct } from "constructs";
33
import { BaseStackProps } from "./props";
44
import { HttpMethods } from "aws-cdk-lib/aws-s3";
55

6+
export interface S3StackProps extends BaseStackProps {
7+
bucketName: string
8+
}
9+
610
export class S3Stack extends Stack {
711
public readonly bucket: aws_s3.Bucket
812

9-
constructor(scope: Construct, id: string, props: BaseStackProps) {
13+
constructor(scope: Construct, id: string, props: S3StackProps) {
1014
super(scope, id, props);
1115

1216
const bucket = new aws_s3.Bucket(this, 'createBucket', {
13-
bucketName: `${ props.stage }-${ props.serviceName }-bucket`,
17+
bucketName: `${ props.bucketName }-bucket`,
1418
versioned: props.stage === 'prd-v0292',
1519
removalPolicy: RemovalPolicy.DESTROY,
1620
autoDeleteObjects: true,

test/__snapshots__/decidim-cfj-cdk.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ exports[`DecidimStack Created 1`] = `
197197
{
198198
"Action": "s3:*",
199199
"Effect": "Allow",
200-
"Resource": "arn:aws:s3:::staging-decidim-bucket*",
200+
"Resource": "arn:aws:s3:::staging-decidim*",
201201
"Sid": "allowS3access",
202202
},
203203
{

test/decidim-cfj-cdk.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ test('DecidimStack Created', () => {
2222
region: config.aws.region
2323
}
2424

25-
const cloudfrontEnv = {
26-
account: config.aws.accountId,
27-
region: 'us-east-1'
28-
}
29-
3025
new S3Stack(app, `${ stage }${ serviceName }S3Stack`, {
3126
stage,
3227
env,
33-
serviceName
28+
serviceName,
29+
bucketName: config.s3Bucket
3430
})
3531

3632
const network = new NetworkStack(app, `${ stage }${ serviceName }NetworkStack`, {
@@ -76,7 +72,8 @@ test('DecidimStack Created', () => {
7672
securityGroupForAlb: network.sgForAlb,
7773
domain: config.domain,
7874
rds: rds.rds.dbInstanceEndpointAddress,
79-
cache: elastiCache.redis.attrReaderEndPointAddress
75+
cache: elastiCache.redis.attrReaderEndPointAddress,
76+
bucketName: config.s3Bucket
8077
};
8178
const stack = new DecidimStack(app, 'DecidimStack', props);
8279

test/s3-stack.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as cdk from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
33

44
import { Config, getConfig } from "../lib/config";
5-
import { NetworkStack } from "../lib/network";
65
import { S3Stack } from "../lib/s3-stack";
76

87
test('S3Stack Created', () => {
@@ -20,7 +19,8 @@ test('S3Stack Created', () => {
2019
const s3stack = new S3Stack(app, `${ stage }${ serviceName }S3Stack`, {
2120
stage,
2221
env,
23-
serviceName
22+
serviceName,
23+
bucketName: config.s3Bucket,
2424
})
2525

2626
const template = Template.fromStack(s3stack);

0 commit comments

Comments
 (0)