Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow legacy option for lambdaHashingVersion property #10173

Merged
merged 1 commit into from Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/deprecations.md
Expand Up @@ -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:

Expand Down
7 changes: 4 additions & 3 deletions lib/plugins/aws/package/compile/functions.js
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/provider.js
Expand Up @@ -1010,7 +1010,7 @@ class AwsProvider {
kmsKeyArn: { $ref: '#/definitions/awsKmsArn' },
lambdaHashingVersion: {
type: 'string',
enum: ['20201221'],
enum: ['20200924', '20201221'],
},
layers: { $ref: '#/definitions/awsLambdaLayers' },
logRetentionInDays: {
Expand Down