Skip to content

Commit

Permalink
fix(AWS Lambda): Ensure version hash is in all cases effective (#8310)
Browse files Browse the repository at this point in the history
In some instances the version hash may change due to a change involving
CloudFormation instrisic functions, but upon resolving the functions, the
resulting lambda configuration is identical to what is currently
deployed. This causes the Lambda::Version to fail to publish since AWS
sees the lambdas as identical.

This commit embeds an environment variable onto each lambda function with
the value of the version config hash, ensuring that anytime the config
hash changes, the resulting lambda configuration will be changed,
allowing a Lambda::Version to be published.
  • Loading branch information
brent-jackson committed Oct 1, 2020
1 parent 4168dc1 commit 73c34b9
Show file tree
Hide file tree
Showing 3 changed files with 364 additions and 58 deletions.
11 changes: 10 additions & 1 deletion lib/plugins/aws/package/compile/functions/index.js
Expand Up @@ -425,7 +425,7 @@ class AwsCompileFunctions {
delete layerConfig.properties.Content.S3Key;
}

// sort the layer conifigurations for hash consistency
// sort the layer configurations for hash consistency
const sortedLayerConfigurations = {};
const byKey = ([key1], [key2]) => key1.localeCompare(key2);
for (const { name, properties: layerProperties } of layerConfigurations) {
Expand Down Expand Up @@ -474,6 +474,15 @@ class AwsCompileFunctions {

Object.assign(cfTemplate.Resources, newVersionObject);

// Add an environment var with a value of the versionDigest to force
// the AWS::Lambda::Function configuration to change whenever the
// versionDigest changes
_.set(
functionResource.Properties,
'Environment.Variables.SLS_LAMBDA_VERSION_DIGEST',
versionDigest
);

// Add function versions to Outputs section
const functionVersionOutputLogicalId = this.provider.naming.getLambdaVersionOutputLogicalId(
functionName
Expand Down

0 comments on commit 73c34b9

Please sign in to comment.