Skip to content

Commit 56a75e4

Browse files
committed
Adding waiter for Lambda Function steps
1 parent 9737f23 commit 56a75e4

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

cloudformation/template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,7 @@ Resources:
18321832
Action:
18331833
- lambda:CreateFunction
18341834
- lambda:GetFunction
1835+
- lambda:GetFunctionConfiguration
18351836
- lambda:UpdateFunctionCode
18361837
- lambda:PublishVersion
18371838
Resource: arn:aws:lambda:*:*:*

lambdas/cloudfront-security/replicator.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,19 @@ exports.handler = async (event, context) => {
5252
if (event.RequestType === 'Create') {
5353
console.log('Creating function')
5454
const createResult = await lambdaEdge.createFunction({
55-
Code: {
56-
ZipFile: zipped
57-
},
58-
Description: '',
59-
FunctionName: functionName,
60-
Handler: 'index.handler',
61-
MemorySize: 128,
62-
Role: event.ResourceProperties.RoleArn,
63-
Runtime: 'nodejs12.x',
64-
Timeout: 1
55+
Code: {
56+
ZipFile: zipped
57+
},
58+
Description: '',
59+
FunctionName: functionName,
60+
Handler: 'index.handler',
61+
MemorySize: 128,
62+
Role: event.ResourceProperties.RoleArn,
63+
Runtime: 'nodejs12.x',
64+
Timeout: 1
6565
}).promise()
66-
66+
await lambdaEdge.waitFor('functionExists', { FunctionName: functionName }).promise()
67+
await lambdaEdge.waitFor('functionActive', { FunctionName: functionName, $waiter: { delay: 2, maxAttempts: 5 } }).promise()
6768
console.log('Publishing initial version')
6869
versionResult = await lambdaEdge.publishVersion({
6970
FunctionName: createResult.FunctionArn
@@ -75,6 +76,7 @@ exports.handler = async (event, context) => {
7576
FunctionName: functionName,
7677
Publish: true
7778
}).promise()
79+
await lambdaEdge.waitFor('functionUpdated', { FunctionName: functionName }).promise()
7880
}
7981

8082
console.log('Saving to S3')

0 commit comments

Comments
 (0)