Skip to content

Commit

Permalink
feat(AWS Lambda): Change default runtime to nodejs14.x
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Default runtime has been changed from `nodejs12.x` to
`nodejs14.x`
  • Loading branch information
pgrzesik authored and medikoo committed Jan 27, 2022
1 parent 6de37bf commit 30e99fb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 116 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/aws/customResources/index.js
Expand Up @@ -173,7 +173,7 @@ async function addCustomResourceToService(awsProvider, resourceName, iamRoleStat
FunctionName: absoluteFunctionName,
Handler,
MemorySize: 1024,
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 180,
},
DependsOn: [],
Expand Down
12 changes: 0 additions & 12 deletions lib/plugins/aws/package/compile/functions.js
Expand Up @@ -50,18 +50,6 @@ class AwsCompileFunctions {
'While it is highly encouraged to upgrade to new algorithm, you can still use the old approach by setting "provider.lambdaHashingVersion" to "20200924".'
);
}
if (
!this.serverless.service.provider.runtime &&
Object.keys(this.serverless.service.functions).length &&
Object.values(this.serverless.service.functions).some(
({ handler, runtime }) => handler && !runtime
)
) {
this.serverless._logDeprecation(
'CHANGE_OF_DEFAULT_RUNTIME_TO_NODEJS14X',
'Starting with `v3.0.0`, the default runtime will change from `nodejs12.x` to `nodejs14.x`. In order to hide the deprecation message and ensure seamless upgrade, please set the runtime explicitly.'
);
}
},
'package:compileFunctions': async () =>
BbPromise.bind(this).then(this.downloadPackageArtifacts).then(this.compileFunctions),
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/provider.js
Expand Up @@ -1595,7 +1595,7 @@ class AwsProvider {
}

getRuntime(runtime) {
const defaultRuntime = 'nodejs12.x';
const defaultRuntime = 'nodejs14.x';
const runtimeSourceValue = this.getRuntimeSourceValue();
return runtime || runtimeSourceValue.value || defaultRuntime;
}
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/programmatic/function/serverless.yml
Expand Up @@ -5,7 +5,6 @@ frameworkVersion: '*'

provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221

functions:
Expand Down
6 changes: 3 additions & 3 deletions test/unit/lib/plugins/aws/customResources/index.test.js
Expand Up @@ -109,7 +109,7 @@ describe('#addCustomResourceToService()', () => {
Role: {
'Fn::GetAtt': ['IamRoleCustomResourcesLambdaExecution', 'Arn'],
},
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 180,
},
DependsOn: ['IamRoleCustomResourcesLambdaExecution'],
Expand All @@ -128,7 +128,7 @@ describe('#addCustomResourceToService()', () => {
Role: {
'Fn::GetAtt': ['IamRoleCustomResourcesLambdaExecution', 'Arn'],
},
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 180,
},
DependsOn: ['IamRoleCustomResourcesLambdaExecution'],
Expand All @@ -147,7 +147,7 @@ describe('#addCustomResourceToService()', () => {
Role: {
'Fn::GetAtt': ['IamRoleCustomResourcesLambdaExecution', 'Arn'],
},
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 180,
},
DependsOn: ['IamRoleCustomResourcesLambdaExecution'],
Expand Down
114 changes: 16 additions & 98 deletions test/unit/lib/plugins/aws/package/compile/functions.test.js
Expand Up @@ -334,7 +334,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
},
};
Expand All @@ -347,51 +347,6 @@ describe('AwsCompileFunctions', () => {
});
});

it('should create a function resource with function level tags', () => {
const s3Folder = awsCompileFunctions.serverless.service.package.artifactDirectoryName;
const s3FileName = awsCompileFunctions.serverless.service.package.artifact
.split(path.sep)
.pop();
awsCompileFunctions.serverless.service.functions = {
func: {
handler: 'func.function.handler',
name: 'new-service-dev-func',
tags: {
foo: 'bar',
baz: 'qux',
},
},
};

const compiledFunction = {
Type: 'AWS::Lambda::Function',
DependsOn: ['FuncLogGroup'],
Properties: {
Code: {
S3Key: `${s3Folder}/${s3FileName}`,
S3Bucket: { Ref: 'ServerlessDeploymentBucket' },
},
FunctionName: 'new-service-dev-func',
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Timeout: 6,
Tags: [
{ Key: 'foo', Value: 'bar' },
{ Key: 'baz', Value: 'qux' },
],
},
};

return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled.then(() => {
expect(
awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate.Resources
.FuncLambdaFunction
).to.deep.equal(compiledFunction);
});
});

describe('when using onError config', () => {
let s3Folder;
let s3FileName;
Expand Down Expand Up @@ -439,7 +394,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: 'arn:aws:sns:region:accountid:foo',
Expand Down Expand Up @@ -490,7 +445,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: {
Expand Down Expand Up @@ -532,7 +487,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: {
Expand Down Expand Up @@ -574,7 +529,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: {
Expand Down Expand Up @@ -616,7 +571,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
DeadLetterConfig: {
TargetArn: 'arn:aws:sns:region:accountid:foo',
Expand Down Expand Up @@ -683,7 +638,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
TracingConfig: {
Mode: 'Active',
Expand Down Expand Up @@ -740,7 +695,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
Environment: {
Variables: {
Expand Down Expand Up @@ -807,7 +762,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 128,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 10,
},
};
Expand All @@ -820,43 +775,6 @@ describe('AwsCompileFunctions', () => {
});
});

it('should default to the nodejs12.x runtime when no provider runtime is given', () => {
const s3Folder = awsCompileFunctions.serverless.service.package.artifactDirectoryName;
const s3FileName = awsCompileFunctions.serverless.service.package.artifact
.split(path.sep)
.pop();
awsCompileFunctions.serverless.service.provider.runtime = null;
awsCompileFunctions.serverless.service.functions = {
func: {
handler: 'func.function.handler',
name: 'new-service-dev-func',
},
};
const compiledFunction = {
Type: 'AWS::Lambda::Function',
DependsOn: ['FuncLogGroup'],
Properties: {
Code: {
S3Key: `${s3Folder}/${s3FileName}`,
S3Bucket: { Ref: 'ServerlessDeploymentBucket' },
},
FunctionName: 'new-service-dev-func',
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Timeout: 6,
},
};

return expect(awsCompileFunctions.compileFunctions()).to.be.fulfilled.then(() => {
expect(
awsCompileFunctions.serverless.service.provider.compiledCloudFormationTemplate.Resources
.FuncLambdaFunction
).to.deep.equal(compiledFunction);
});
});

it('should include description if specified', () => {
awsCompileFunctions.serverless.service.functions = {
func: {
Expand Down Expand Up @@ -978,7 +896,7 @@ describe('AwsCompileFunctions', () => {
MemorySize: 1024,
ReservedConcurrentExecutions: 5,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -1034,7 +952,7 @@ describe('AwsCompileFunctions', () => {
MemorySize: 1024,
ReservedConcurrentExecutions: 0,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -1073,7 +991,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
},
};
Expand Down Expand Up @@ -1111,7 +1029,7 @@ describe('AwsCompileFunctions', () => {
Handler: 'func.function.handler',
MemorySize: 1024,
Role: { 'Fn::GetAtt': ['IamRoleLambdaExecution', 'Arn'] },
Runtime: 'nodejs12.x',
Runtime: 'nodejs14.x',
Timeout: 6,
Layers: ['arn:aws:xxx:*:*'],
},
Expand Down Expand Up @@ -1868,9 +1786,9 @@ describe('lib/plugins/aws/package/compile/functions/index.test.js', () => {
// https://github.com/serverless/serverless/blob/d8527d8b57e7e5f0b94ba704d9f53adb34298d99/lib/plugins/aws/package/compile/functions/index.test.js#L1784-L1820
});

it.skip('TODO: should default to "nodejs12.x" runtime`', () => {
// Replacement for
// https://github.com/serverless/serverless/blob/d8527d8b57e7e5f0b94ba704d9f53adb34298d99/lib/plugins/aws/package/compile/functions/index.test.js#L1864-L1899
it('should default to "nodejs14.x" runtime`', () => {
const funcResource = cfResources[naming.getLambdaLogicalId('target')];
expect(funcResource.Properties.Runtime).to.equal('nodejs14.x');
});

it.skip('TODO: should support `functions[].runtime`', () => {
Expand Down

0 comments on commit 30e99fb

Please sign in to comment.