diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js index 66107295e37..b8a2940071f 100644 --- a/lib/plugins/aws/package/compile/functions/index.js +++ b/lib/plugins/aws/package/compile/functions/index.js @@ -409,6 +409,11 @@ class AwsCompileFunctions { } } + const versionFunction = + functionObject.versionFunction != null + ? functionObject.versionFunction + : this.serverless.service.provider.versionFunctions; + if (functionObject.provisionedConcurrency) { const provisionedConcurrency = _.parseInt(functionObject.provisionedConcurrency); @@ -449,8 +454,6 @@ class AwsCompileFunctions { newFunctionObject ); - const newVersion = this.cfLambdaVersionTemplate(); - // Create hashes for the artifact and the logical id of the version resource // The one for the version resource must include the function configuration // to make sure that a new version is created on configuration changes and @@ -490,6 +493,10 @@ class AwsCompileFunctions { const fileDigest = fileHash.read(); const versionDigest = versionHash.read(); + if (!versionFunction) return; + + const newVersion = this.cfLambdaVersionTemplate(); + newVersion.Properties.CodeSha256 = fileDigest; newVersion.Properties.FunctionName = { Ref: functionLogicalId }; if (functionObject.description) { @@ -506,17 +513,10 @@ class AwsCompileFunctions { [versionLogicalId]: newVersion, }; - const versionFunction = - functionObject.versionFunction != null - ? functionObject.versionFunction - : this.serverless.service.provider.versionFunctions; - - if (versionFunction) { - _.merge( - this.serverless.service.provider.compiledCloudFormationTemplate.Resources, - newVersionObject - ); - } + _.merge( + this.serverless.service.provider.compiledCloudFormationTemplate.Resources, + newVersionObject + ); // Add function versions to Outputs section const functionVersionOutputLogicalId = this.provider.naming.getLambdaVersionOutputLogicalId( @@ -526,13 +526,9 @@ class AwsCompileFunctions { newVersionOutput.Value = { Ref: versionLogicalId }; - if (versionFunction) { - _.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Outputs, { - [functionVersionOutputLogicalId]: newVersionOutput, - }); - } - - return BbPromise.resolve(); + _.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Outputs, { + [functionVersionOutputLogicalId]: newVersionOutput, + }); }); }