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..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 @@ -76,6 +76,25 @@ 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, + $waiter: { + maxAttempts: 1, + }, + }) + .promise(), + ); + } catch (error) { + throw new Error(`Unable to find S3 object s3://${outputBucketName}/${outputPath}: ${error}`); + } } async function onUpdate(event: CloudFormationCustomResourceEvent) {