From 0aa90b202f61476e31c0e511b8e46b3fb876153e Mon Sep 17 00:00:00 2001 From: nachundu Date: Wed, 16 Sep 2020 13:20:51 +0530 Subject: [PATCH 1/2] added wait for object exists in the account bucket --- .../cdk-s3-template/runtime/src/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts b/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts index d7630fd9b..416b2d835 100644 --- a/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts +++ b/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts @@ -76,6 +76,22 @@ async function onCreate(event: CloudFormationCustomResourceEvent) { } catch (e) { throw new Error(`Unable to put S3 object s3://${outputBucketName}/${outputPath}: ${e}`); } + + try { + // Waiting for the template available in s3 + // default delay is 5 seconds and max retry attempts is 20 + console.debug(`Waiting for ${outputBucketName}/${outputPath}`); + await throttlingBackOff(() => + s3 + .waitFor('objectExists', { + Bucket: outputBucketName, + Key: outputPath, + }) + .promise(), + ); + } catch (error) { + throw new Error(`Unable to find S3 object s3://${outputBucketName}/${outputPath}: ${error}`); + } } async function onUpdate(event: CloudFormationCustomResourceEvent) { From 1fb59a02f98573da672df5b596ef70e130d95ef6 Mon Sep 17 00:00:00 2001 From: nachundu Date: Wed, 16 Sep 2020 15:16:56 +0530 Subject: [PATCH 2/2] updated max attempts to 1 b/w delay of 5 seconds --- src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts b/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts index 416b2d835..b7abe812b 100644 --- a/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts +++ b/src/lib/custom-resources/cdk-s3-template/runtime/src/index.ts @@ -86,6 +86,9 @@ async function onCreate(event: CloudFormationCustomResourceEvent) { .waitFor('objectExists', { Bucket: outputBucketName, Key: outputPath, + $waiter: { + maxAttempts: 1, + }, }) .promise(), );