From 2c74f720f912ea746a83a7b2f6fb38c6f61db421 Mon Sep 17 00:00:00 2001 From: Piotr Grzesik Date: Thu, 28 Oct 2021 15:43:44 +0200 Subject: [PATCH] feat: Allow `legacy` option for `lambdaHashingVersion` property --- docs/deprecations.md | 6 ++++-- lib/plugins/aws/package/compile/functions.js | 7 ++++--- lib/plugins/aws/provider.js | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/deprecations.md b/docs/deprecations.md index 8ceae7e5224..69b39758255 100644 --- a/docs/deprecations.md +++ b/docs/deprecations.md @@ -322,9 +322,11 @@ Org, app, service, stage, and region are required to resolve variables when logg Deprecation code: `LAMBDA_HASHING_VERSION_V2` -Resolution of lambda version hashes was improved with better (fixed deterministism issues) algorithm, which will be used starting with v3.0.0 +Lambda version hashes were improved with a better algorithm (that fixed determinism issues). It will be used by default starting with v3.0.0. -You can adapt your services to use it now, by setting `provider.lambdaHashingVersion` to `20201221`. +You can adapt your services to use it now by setting `provider.lambdaHashingVersion` to `20201221`. + +While not recommended, you can keep using the old hashing algorithm by setting `provider.lambdaHashingVersion` to `20200924`. That will silence the deprecation and allow to upgrade to v3. **Notice:** If you apply this on already deployed service without any changes to lambda code, you might encounter an error similar to the one below: diff --git a/lib/plugins/aws/package/compile/functions.js b/lib/plugins/aws/package/compile/functions.js index 105fa0c8ebe..7b1803a2010 100644 --- a/lib/plugins/aws/package/compile/functions.js +++ b/lib/plugins/aws/package/compile/functions.js @@ -62,7 +62,8 @@ class AwsCompileFunctions { 'LAMBDA_HASHING_VERSION_V2', 'Resolution of lambda version hashes was improved with better algorithm, ' + 'which will be used in next major release.\n' + - 'Switch to it now by setting "provider.lambdaHashingVersion" to "20201221"' + 'Switch to it now by setting "provider.lambdaHashingVersion" to "20201221".\n' + + 'While it is highly encouraged to upgrade to new algorithm, you can still use the old approach by setting "provider.lambdaHashingVersion" to "20200924".' ); } if ( @@ -147,7 +148,7 @@ class AwsCompileFunctions { async addFileToHash(filePath, hash) { const lambdaHashingVersion = this.serverless.service.provider.lambdaHashingVersion; - if (lambdaHashingVersion) { + if (lambdaHashingVersion >= 20201221) { const filePathHash = await getHashForFilePath(filePath); hash.write(filePathHash); } else { @@ -502,7 +503,7 @@ class AwsCompileFunctions { delete functionProperties.Tags; const lambdaHashingVersion = this.serverless.service.provider.lambdaHashingVersion; - if (lambdaHashingVersion) { + if (lambdaHashingVersion >= 20201221) { functionProperties.layerConfigurations = layerConfigurations; versionHash.write(JSON.stringify(deepSortObjectByKey(functionProperties))); } else { diff --git a/lib/plugins/aws/provider.js b/lib/plugins/aws/provider.js index 4703b9ded04..4f6302ce41f 100644 --- a/lib/plugins/aws/provider.js +++ b/lib/plugins/aws/provider.js @@ -1010,7 +1010,7 @@ class AwsProvider { kmsKeyArn: { $ref: '#/definitions/awsKmsArn' }, lambdaHashingVersion: { type: 'string', - enum: ['20201221'], + enum: ['20200924', '20201221'], }, layers: { $ref: '#/definitions/awsLambdaLayers' }, logRetentionInDays: {