Skip to content

Commit 30e0731

Browse files
committed
refactor
1 parent 25629c3 commit 30e0731

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ cdk-deploy: guard-STACK_NAME
9898
--context logRetentionInDays=$$LOG_RETENTION_IN_DAYS \
9999
--context slackBotToken=$$SLACK_BOT_TOKEN \
100100
--context slackSigningSecret=$$SLACK_SIGNING_SECRET
101-
102101
cdk-synth:
103102
npx cdk synth \
104103
--quiet \
@@ -109,7 +108,8 @@ cdk-synth:
109108
--context commitId=undefined \
110109
--context logRetentionInDays=30 \
111110
--context slackBotToken=dummy \
112-
--context slackSigningSecret=dummy
111+
--context slackSigningSecret=dummy \
112+
--context cfnDriftDetectionGroup=dummy
113113
./scripts/fix_cfn_guard.sh
114114

115115
cdk-diff:

packages/cdk/constructs/DynamoDbTable.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ export class DynamoDbTable extends Construct {
2828
constructor(scope: Construct, id: string, props: DynamoDbTableProps) {
2929
super(scope, id)
3030

31-
this.kmsKey = new Key(this, "TableKey", {
31+
const kmsKey = new Key(this, "TableKey", {
3232
enableKeyRotation: true,
3333
description: `KMS key for ${props.tableName} DynamoDB table encryption`,
3434
removalPolicy: RemovalPolicy.DESTROY
3535
})
3636

37-
this.kmsKey.addAlias(`alias/${props.tableName}-dynamodb-key`)
37+
kmsKey.addAlias(`alias/${props.tableName}-dynamodb-key`)
3838

39-
this.table = new TableV2(this, props.tableName, {
39+
const table = new TableV2(this, props.tableName, {
4040
tableName: props.tableName,
4141
partitionKey: props.partitionKey,
4242
sortKey: props.sortKey,
@@ -46,7 +46,10 @@ export class DynamoDbTable extends Construct {
4646
pointInTimeRecoveryEnabled: true
4747
},
4848
removalPolicy: RemovalPolicy.DESTROY,
49-
encryption: TableEncryptionV2.customerManagedKey(this.kmsKey)
49+
encryption: TableEncryptionV2.customerManagedKey(kmsKey)
5050
})
51+
52+
this.kmsKey = kmsKey
53+
this.table = table
5154
}
5255
}

packages/cdk/constructs/LambdaFunction.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export interface LambdaFunctionProps {
2626
readonly handler: string
2727
readonly environmentVariables: {[key: string]: string}
2828
readonly additionalPolicies?: Array<IManagedPolicy>
29-
readonly role?: Role
3029
readonly logRetentionInDays: number
3130
readonly logLevel: string
3231
}
@@ -111,20 +110,10 @@ export class LambdaFunction extends Construct {
111110
...(props.additionalPolicies ?? [])
112111
]
113112

114-
// Use provided role or create new one with required policies
115-
let role: Role
116-
if (props.role) {
117-
role = props.role
118-
// Attach any missing managed policies to the provided role
119-
for (const policy of requiredPolicies) {
120-
role.addManagedPolicy(policy)
121-
}
122-
} else {
123-
role = new Role(this, "LambdaRole", {
124-
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
125-
managedPolicies: requiredPolicies
126-
})
127-
}
113+
const role = new Role(this, "LambdaRole", {
114+
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
115+
managedPolicies: requiredPolicies
116+
})
128117

129118
// Create Lambda function with Python runtime and monitoring
130119
const lambdaFunction = new LambdaFunctionResource(this, props.functionName, {

packages/cdk/constructs/S3Bucket.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ export class S3Bucket extends Construct {
2020
constructor(scope: Construct, id: string, props: S3BucketProps) {
2121
super(scope, id)
2222

23-
this.kmsKey = new Key(this, "BucketKey", {
23+
const kmsKey = new Key(this, "BucketKey", {
2424
enableKeyRotation: true,
2525
description: `KMS key for ${props.bucketName} S3 bucket encryption`,
2626
removalPolicy: RemovalPolicy.DESTROY
2727
})
28-
this.kmsKey.addAlias(`alias/${props.bucketName}-s3-key`)
28+
kmsKey.addAlias(`alias/${props.bucketName}-s3-key`)
2929

30-
this.bucket = new Bucket(this, props.bucketName, {
30+
const bucket = new Bucket(this, props.bucketName, {
3131
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
3232
encryption: BucketEncryption.KMS,
3333
encryptionKey: this.kmsKey,
@@ -37,5 +37,8 @@ export class S3Bucket extends Construct {
3737
versioned: props.versioned ?? false,
3838
objectOwnership: ObjectOwnership.BUCKET_OWNER_ENFORCED
3939
})
40+
41+
this.kmsKey = kmsKey
42+
this.bucket = bucket
4043
}
4144
}

packages/cdk/constructs/SecretWithParameter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ export class SecretWithParameter extends Construct {
1818
super(scope, id)
1919

2020
// Create secret in AWS Secrets Manager
21-
this.secret = new Secret(this, "Secret", {
21+
const secret = new Secret(this, "Secret", {
2222
secretName: props.secretName,
2323
description: props.description,
2424
secretStringValue: SecretValue.unsafePlainText(props.secretValue)
2525
})
2626

2727
// Create SSM parameter that references the secret
28-
this.parameter = new StringParameter(this, "Parameter", {
28+
const parameter = new StringParameter(this, "Parameter", {
2929
parameterName: props.parameterName,
30-
stringValue: `{{resolve:secretsmanager:${this.secret.secretName}}}`,
30+
stringValue: `{{resolve:secretsmanager:${secret.secretName}}}`,
3131
description: `Reference to ${props.description}`,
3232
tier: ParameterTier.STANDARD
3333
})
34+
35+
this.secret = secret
36+
this.parameter = parameter
3437
}
3538
}

0 commit comments

Comments
 (0)