Skip to content

Commit 2396266

Browse files
authored
fix-adding-payload-hash-in-physical-res-id (#5)
re-adding function config (payload hash) as part of the physicalResourceId
1 parent 63626b9 commit 2396266

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/resource-initializer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Construct, Duration, Stack } from '@aws-cdk/core'
77
import { AwsCustomResource, AwsCustomResourcePolicy, AwsSdkCall, PhysicalResourceId } from '@aws-cdk/custom-resources'
88
import { RetentionDays } from '@aws-cdk/aws-logs'
99
import { PolicyStatement, Role, ServicePrincipal } from '@aws-cdk/aws-iam'
10+
import { createHash } from 'crypto'
1011

1112
export interface CdkResourceInitializerProps {
1213
vpc: ec2.IVpc
@@ -53,14 +54,16 @@ export class CdkResourceInitializer extends Construct {
5354
}
5455
})
5556

57+
const payloadHashPrefix = createHash('md5').update(payload).digest('hex').substring(0, 6)
58+
5659
const sdkCall: AwsSdkCall = {
5760
service: 'Lambda',
5861
action: 'invoke',
5962
parameters: {
6063
FunctionName: fn.functionName,
6164
Payload: payload
6265
},
63-
physicalResourceId: PhysicalResourceId.of(`${id}-AwsSdkCall-${fn.currentVersion.version}`)
66+
physicalResourceId: PhysicalResourceId.of(`${id}-AwsSdkCall-${fn.currentVersion.version + payloadHashPrefix}`)
6467
}
6568

6669
// IMPORTANT: the AwsCustomResource construct deploys a singleton AWS Lambda function that is re-used across the same CDK Stack,

0 commit comments

Comments
 (0)