@@ -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