From 64c9d97eb0350a1c79f556bfec63d7292b9eaf4d Mon Sep 17 00:00:00 2001 From: Malcolm Landon Date: Wed, 7 Sep 2022 14:04:11 +0100 Subject: [PATCH] fix: plat-5908 add dependency to cdn-site-hosting construct (#63) --- lib/cdn-site-hosting/cdn-site-hosting-construct.ts | 4 ++++ .../cdn-site-hosting/cdn-site-hosting-construct.test.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/cdn-site-hosting/cdn-site-hosting-construct.ts b/lib/cdn-site-hosting/cdn-site-hosting-construct.ts index 0efce377..1219e6e0 100644 --- a/lib/cdn-site-hosting/cdn-site-hosting-construct.ts +++ b/lib/cdn-site-hosting/cdn-site-hosting-construct.ts @@ -135,6 +135,10 @@ export class CdnSiteHostingConstruct extends cdk.Construct { } ); + // Give the first deployment a dependency on the s3 bucket. + // Without this, we may start copying files into the s3 bucket before it has been created. + deployments[0].node.addDependency(this.s3Bucket); + // Now make the rest of the deployments dependent on the previous one. deployments.forEach((deployment, deploymentIndex) => { if (deploymentIndex > 0) { deployment.node.addDependency(deployments[deploymentIndex - 1]); diff --git a/test/infra/cdn-site-hosting/cdn-site-hosting-construct.test.ts b/test/infra/cdn-site-hosting/cdn-site-hosting-construct.test.ts index 90254aec..a803bc24 100644 --- a/test/infra/cdn-site-hosting/cdn-site-hosting-construct.test.ts +++ b/test/infra/cdn-site-hosting/cdn-site-hosting-construct.test.ts @@ -302,7 +302,10 @@ describe("CdnSiteHostingConstruct", () => { expect(deployments.length).toBe(2); const [[firstDeploymentId, firstDeployment], [, secondDeployment]] = deployments; - expect(firstDeployment.DependsOn).toBeUndefined(); + expect(firstDeployment.DependsOn).toBeDefined(); + expect(firstDeployment.DependsOn).toContain( + "MyTestConstructSiteBucketEE4FFC1B" + ); expect(secondDeployment.DependsOn).toBeDefined(); expect(secondDeployment.DependsOn).toContain(firstDeploymentId); });