Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 0f54908

Browse files
committed
fixed website resource race condition when deploying through cloudformation
1 parent e3b44bc commit 0f54908

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

source/infrastructure/lib/s3web/static-site.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,6 @@ export class StaticWebsite extends Construct {
8181
iam.Role.fromRoleArn(this, 'BucketPolicyLambdaRole', props.customResourceRoleArn)
8282
);
8383

84-
const bucketPolicyUpdateCustomResource = new cdk.CustomResource(this, 'UpdateBucketPolicy', {
85-
resourceType: 'Custom::UpdateBucketPolicy',
86-
serviceToken: props.customResourceLambdaArn,
87-
properties: {
88-
Resource: 'UPDATE_BUCKET_POLICY',
89-
SOURCE_BUCKET_NAME: this.webS3Bucket.bucketName,
90-
LOGGING_BUCKET_NAME: props.accessLoggingBucket.bucketName,
91-
SOURCE_PREFIX: 'webappbucket'
92-
}
93-
});
94-
bucketPolicyUpdateCustomResource.node.addDependency(bucketPolicyForLambda);
95-
9684
const cloudfrontToS3 = new CloudFrontToS3(this, 'UI', {
9785
existingBucketObj: this.webS3Bucket,
9886
cloudFrontDistributionProps: {
@@ -109,7 +97,21 @@ export class StaticWebsite extends Construct {
10997

11098
const cloudFrontLogsLoggingPrefix = 'cloudfrontlogs-logging';
11199

112-
const cloudFrontLoggingUpdateBucketPolicy = new cdk.CustomResource(
100+
const bucketPolicyUpdateCustomResource = new cdk.CustomResource(this, 'UpdateBucketPolicy', {
101+
resourceType: 'Custom::UpdateBucketPolicy',
102+
serviceToken: props.customResourceLambdaArn,
103+
properties: {
104+
Resource: 'UPDATE_BUCKET_POLICY',
105+
SOURCE_BUCKET_NAME: this.webS3Bucket.bucketName,
106+
LOGGING_BUCKET_NAME: props.accessLoggingBucket.bucketName,
107+
SOURCE_PREFIX: 'webappbucket'
108+
}
109+
});
110+
bucketPolicyUpdateCustomResource.node.addDependency(bucketPolicyForLambda);
111+
bucketPolicyUpdateCustomResource.node.addDependency(this.webS3Bucket.policy!);
112+
bucketPolicyUpdateCustomResource.node.addDependency(cloudfrontToS3.cloudFrontWebDistribution);
113+
114+
const cloudFrontLoggingUpdateBucketPolicyCustomResource = new cdk.CustomResource(
113115
this,
114116
'CloudFrontLoggingUpdateBucketPolicy',
115117
{
@@ -123,8 +125,11 @@ export class StaticWebsite extends Construct {
123125
}
124126
}
125127
);
126-
127-
cloudFrontLoggingUpdateBucketPolicy.node.addDependency(bucketPolicyForLambda);
128+
cloudFrontLoggingUpdateBucketPolicyCustomResource.node.addDependency(bucketPolicyUpdateCustomResource);
129+
cloudFrontLoggingUpdateBucketPolicyCustomResource.node.addDependency(
130+
cloudfrontToS3.cloudFrontLoggingBucket!.policy!
131+
);
132+
cloudFrontLoggingUpdateBucketPolicyCustomResource.node.addDependency(cloudfrontToS3.cloudFrontWebDistribution);
128133

129134
const cfnCloudFrontLoggingBucket = cloudfrontToS3.cloudFrontLoggingBucket?.node.defaultChild as s3.CfnBucket;
130135
cfnCloudFrontLoggingBucket.addPropertyOverride('LoggingConfiguration', {

0 commit comments

Comments
 (0)