diff --git a/lib/plugins/aws/package/compile/functions/index.js b/lib/plugins/aws/package/compile/functions/index.js index 85cb3ae4a..5faae064e 100644 --- a/lib/plugins/aws/package/compile/functions/index.js +++ b/lib/plugins/aws/package/compile/functions/index.js @@ -118,6 +118,7 @@ class AwsCompileFunctions { compileFunction(functionName) { return BbPromise.try(() => { + const cfTemplate = this.serverless.service.provider.compiledCloudFormationTemplate; const functionResource = this.cfLambdaFunctionTemplate(); const functionObject = this.serverless.service.getFunction(functionName); functionObject.package = functionObject.package || {}; @@ -213,8 +214,7 @@ class AwsCompileFunctions { const splittedArn = arn.split(':'); if (splittedArn[0] === 'arn' && (splittedArn[2] === 'sns' || splittedArn[2] === 'sqs')) { const dlqType = splittedArn[2]; - const iamRoleLambdaExecution = this.serverless.service.provider - .compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution; + const iamRoleLambdaExecution = cfTemplate.Resources.IamRoleLambdaExecution; let stmt; functionResource.Properties.DeadLetterConfig = { @@ -271,8 +271,7 @@ class AwsCompileFunctions { if (typeof arn === 'string') { const splittedArn = arn.split(':'); if (splittedArn[0] === 'arn' && splittedArn[2] === 'kms') { - const iamRoleLambdaExecution = this.serverless.service.provider - .compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution; + const iamRoleLambdaExecution = cfTemplate.Resources.IamRoleLambdaExecution; functionResource.Properties.KmsKeyArn = arn; @@ -318,8 +317,7 @@ class AwsCompileFunctions { mode = 'Active'; } - const iamRoleLambdaExecution = this.serverless.service.provider - .compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution; + const iamRoleLambdaExecution = cfTemplate.Resources.IamRoleLambdaExecution; functionResource.Properties.TracingConfig = { Mode: mode, @@ -436,10 +434,7 @@ class AwsCompileFunctions { [functionLogicalId]: functionResource, }; - Object.assign( - this.serverless.service.provider.compiledCloudFormationTemplate.Resources, - newFunctionObject - ); + Object.assign(cfTemplate.Resources, newFunctionObject); const shouldVersionFunction = functionObject.versionFunction != null @@ -467,9 +462,7 @@ class AwsCompileFunctions { ); } - this.serverless.service.provider.compiledCloudFormationTemplate.Resources[ - this.provider.naming.getLambdaOnlyVersionLogicalId(functionName) - ] = { + cfTemplate.Resources[this.provider.naming.getLambdaOnlyVersionLogicalId(functionName)] = { Type: 'AWS::Lambda::Version', Properties: { FunctionName: { Ref: functionLogicalId }, @@ -539,10 +532,7 @@ class AwsCompileFunctions { [versionLogicalId]: versionResource, }; - Object.assign( - this.serverless.service.provider.compiledCloudFormationTemplate.Resources, - newVersionObject - ); + Object.assign(cfTemplate.Resources, newVersionObject); // Add function versions to Outputs section const functionVersionOutputLogicalId = this.provider.naming.getLambdaVersionOutputLogicalId( @@ -552,7 +542,7 @@ class AwsCompileFunctions { newVersionOutput.Value = { Ref: versionLogicalId }; - Object.assign(this.serverless.service.provider.compiledCloudFormationTemplate.Outputs, { + Object.assign(cfTemplate.Outputs, { [functionVersionOutputLogicalId]: newVersionOutput, }); });