diff --git a/cloudformation/template.yaml b/cloudformation/template.yaml index bcf8f0f31..f4e010c27 100644 --- a/cloudformation/template.yaml +++ b/cloudformation/template.yaml @@ -1832,6 +1832,7 @@ Resources: Action: - lambda:CreateFunction - lambda:GetFunction + - lambda:GetFunctionConfiguration - lambda:UpdateFunctionCode - lambda:PublishVersion Resource: arn:aws:lambda:*:*:* diff --git a/lambdas/cloudfront-security/replicator.js b/lambdas/cloudfront-security/replicator.js index b9686d93f..030f9e4d4 100644 --- a/lambdas/cloudfront-security/replicator.js +++ b/lambdas/cloudfront-security/replicator.js @@ -52,18 +52,19 @@ exports.handler = async (event, context) => { if (event.RequestType === 'Create') { console.log('Creating function') const createResult = await lambdaEdge.createFunction({ - Code: { - ZipFile: zipped - }, - Description: '', - FunctionName: functionName, - Handler: 'index.handler', - MemorySize: 128, - Role: event.ResourceProperties.RoleArn, - Runtime: 'nodejs12.x', - Timeout: 1 + Code: { + ZipFile: zipped + }, + Description: '', + FunctionName: functionName, + Handler: 'index.handler', + MemorySize: 128, + Role: event.ResourceProperties.RoleArn, + Runtime: 'nodejs12.x', + Timeout: 1 }).promise() - + await lambdaEdge.waitFor('functionExists', { FunctionName: functionName }).promise() + await lambdaEdge.waitFor('functionActive', { FunctionName: functionName, $waiter: { delay: 2, maxAttempts: 5 } }).promise() console.log('Publishing initial version') versionResult = await lambdaEdge.publishVersion({ FunctionName: createResult.FunctionArn @@ -75,6 +76,7 @@ exports.handler = async (event, context) => { FunctionName: functionName, Publish: true }).promise() + await lambdaEdge.waitFor('functionUpdated', { FunctionName: functionName }).promise() } console.log('Saving to S3')