Skip to content

Commit

Permalink
Adding waiter for Lambda Function steps
Browse files Browse the repository at this point in the history
  • Loading branch information
philcaixeta committed Dec 3, 2021
1 parent 9737f23 commit 56a75e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions cloudformation/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,7 @@ Resources:
Action:
- lambda:CreateFunction
- lambda:GetFunction
- lambda:GetFunctionConfiguration
- lambda:UpdateFunctionCode
- lambda:PublishVersion
Resource: arn:aws:lambda:*:*:*
Expand Down
24 changes: 13 additions & 11 deletions lambdas/cloudfront-security/replicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit 56a75e4

Please sign in to comment.