@@ -38,7 +38,10 @@ const {
3838 UntagResourceCommand,
3939 UpdateEventSourceMappingCommand,
4040 UpdateFunctionCodeCommand,
41- UpdateFunctionConfigurationCommand
41+ UpdateFunctionConfigurationCommand,
42+ GetAliasCommand,
43+ CreateAliasCommand,
44+ UpdateAliasCommand
4245} = require ( '@aws-sdk/client-lambda' )
4346
4447const maxBufferSize = 50 * 1024 * 1024
@@ -251,8 +254,7 @@ Emulate only the body of the API Gateway event.
251254 _params ( program , buffer ) {
252255 const params = {
253256 FunctionName : program . functionName +
254- ( program . environment ? '-' + program . environment : '' ) +
255- ( program . lambdaVersion ? '-' + program . lambdaVersion : '' ) ,
257+ ( program . environment ? '-' + program . environment : '' ) ,
256258 Code : { } ,
257259 Handler : program . handler ,
258260 Role : program . role ,
@@ -262,6 +264,7 @@ Emulate only the body of the API Gateway event.
262264 Timeout : Number ( program . timeout ) ,
263265 Architectures : program . architecture ? [ program . architecture ] : [ 'x86_64' ] ,
264266 Publish : ( ( ) => {
267+ if ( program . lambdaVersion ) return true
265268 if ( typeof program . publish === 'boolean' ) {
266269 return program . publish
267270 }
@@ -654,6 +657,29 @@ Emulate only the body of the API Gateway event.
654657 }
655658 }
656659
660+ async _alias ( lambda , functionName , functionVersion , aliasName ) {
661+ try {
662+ await lambda . send ( new GetAliasCommand ( {
663+ FunctionName : functionName ,
664+ Name : aliasName
665+ } ) )
666+ return lambda . send ( new UpdateAliasCommand ( {
667+ FunctionName : functionName ,
668+ Name : aliasName ,
669+ FunctionVersion : functionVersion
670+ } ) )
671+ } catch ( err ) {
672+ if ( err . name === 'ResourceNotFoundException' ) {
673+ return lambda . send ( new CreateAliasCommand ( {
674+ FunctionName : functionName ,
675+ Name : aliasName ,
676+ FunctionVersion : functionVersion
677+ } ) )
678+ }
679+ throw err
680+ }
681+ }
682+
657683 async _uploadExisting ( lambda , params ) {
658684 const functionCodeParams = Object . assign ( {
659685 FunctionName : params . FunctionName ,
@@ -683,7 +709,7 @@ Emulate only the body of the API Gateway event.
683709 delete functionConfigParams . Layers
684710 }
685711
686- const updateConfigResponse = await lambda . send ( new UpdateFunctionConfigurationCommand ( functionConfigParams ) )
712+ await lambda . send ( new UpdateFunctionConfigurationCommand ( functionConfigParams ) )
687713
688714 // Wait for the `Configuration.LastUpdateStatus` to change from `InProgress` to `Successful`.
689715 const getFunction = new GetFunctionCommand ( { FunctionName : params . FunctionName } )
@@ -694,9 +720,7 @@ Emulate only the body of the API Gateway event.
694720 }
695721 await new Promise ( ( resolve ) => setTimeout ( resolve , 3000 ) )
696722 }
697- lambda . send ( new UpdateFunctionCodeCommand ( functionCodeParams ) )
698-
699- return updateConfigResponse
723+ return lambda . send ( new UpdateFunctionCodeCommand ( functionCodeParams ) )
700724 }
701725
702726 _uploadNew ( lambda , params ) {
@@ -1025,7 +1049,10 @@ they may not work as expected in the Lambda environment.
10251049 cloudWatchLogs ,
10261050 program ,
10271051 params . FunctionName
1028- )
1052+ ) ,
1053+ ...( params . Publish && program . lambdaVersion
1054+ ? [ this . _alias ( lambdaClient , params . FunctionName , results . Version , program . lambdaVersion ) ]
1055+ : [ ] )
10291056 ] )
10301057 } else {
10311058 const results = await this . _uploadNew ( lambdaClient , params )
@@ -1053,7 +1080,10 @@ they may not work as expected in the Lambda environment.
10531080 cloudWatchLogs ,
10541081 program ,
10551082 params . FunctionName
1056- )
1083+ ) ,
1084+ ...( params . Publish && program . lambdaVersion
1085+ ? [ this . _alias ( lambdaClient , params . FunctionName , results . Version , program . lambdaVersion ) ]
1086+ : [ ] )
10571087 ] )
10581088 }
10591089 }
0 commit comments