Skip to content

Commit

Permalink
feat(lambda): allow inline code for nodejs12.x runtime (#5710)
Browse files Browse the repository at this point in the history
* chore(lambda): new runtimes support inline code

The nodejs12.x and python3.8 Lambda runtimes actually support inline code.

This reverts commit feb1f9b.

* Python3.8 doesn't support inline code yet

* add integ test

* add missing expected.json

Co-authored-by: Niranjan Jayakar <16217941+nija-at@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 16, 2020
1 parent 8c43425 commit a1cd743
Show file tree
Hide file tree
Showing 3 changed files with 335 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Runtime {
/** @deprecated Use {@link NODEJS_10_X} */
public static readonly NODEJS_8_10 = new Runtime('nodejs8.10', RuntimeFamily.NODEJS, { supportsInlineCode: true });
public static readonly NODEJS_10_X = new Runtime('nodejs10.x', RuntimeFamily.NODEJS, { supportsInlineCode: true });
public static readonly NODEJS_12_X = new Runtime('nodejs12.x', RuntimeFamily.NODEJS);
public static readonly NODEJS_12_X = new Runtime('nodejs12.x', RuntimeFamily.NODEJS, { supportsInlineCode: true });
public static readonly PYTHON_2_7 = new Runtime('python2.7', RuntimeFamily.PYTHON, { supportsInlineCode: true });
public static readonly PYTHON_3_6 = new Runtime('python3.6', RuntimeFamily.PYTHON, { supportsInlineCode: true });
public static readonly PYTHON_3_7 = new Runtime('python3.7', RuntimeFamily.PYTHON, { supportsInlineCode: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
{
"Resources": {
"NODEJS10XServiceRole2FD24B65": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"NODEJS10XF3831960": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "exports.handler = async function(event) { return \"success\" }"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"NODEJS10XServiceRole2FD24B65",
"Arn"
]
},
"Runtime": "nodejs10.x"
},
"DependsOn": [
"NODEJS10XServiceRole2FD24B65"
]
},
"NODEJS12XServiceRole59E71436": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"NODEJS12X8B8075A4": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "exports.handler = async function(event) { return \"success\" }"
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"NODEJS12XServiceRole59E71436",
"Arn"
]
},
"Runtime": "nodejs12.x"
},
"DependsOn": [
"NODEJS12XServiceRole59E71436"
]
},
"PYTHON27ServiceRoleF484A17D": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"PYTHON27F8E941FA": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "def handler(event, context):\n return \"success\""
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"PYTHON27ServiceRoleF484A17D",
"Arn"
]
},
"Runtime": "python2.7"
},
"DependsOn": [
"PYTHON27ServiceRoleF484A17D"
]
},
"PYTHON36ServiceRole814B3AD9": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"PYTHON364935EF15": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "def handler(event, context):\n return \"success\""
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"PYTHON36ServiceRole814B3AD9",
"Arn"
]
},
"Runtime": "python3.6"
},
"DependsOn": [
"PYTHON36ServiceRole814B3AD9"
]
},
"PYTHON37ServiceRoleDE7E561E": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
]
}
]
}
},
"PYTHON37D3A10E04": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": "def handler(event, context):\n return \"success\""
},
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"PYTHON37ServiceRoleDE7E561E",
"Arn"
]
},
"Runtime": "python3.7"
},
"DependsOn": [
"PYTHON37ServiceRoleDE7E561E"
]
}
},
"Outputs": {
"NODEJS10XfunctionName": {
"Value": {
"Ref": "NODEJS10XF3831960"
}
},
"NODEJS12XfunctionName": {
"Value": {
"Ref": "NODEJS12X8B8075A4"
}
},
"PYTHON27functionName": {
"Value": {
"Ref": "PYTHON27F8E941FA"
}
},
"PYTHON36functionName": {
"Value": {
"Ref": "PYTHON364935EF15"
}
},
"PYTHON37functionName": {
"Value": {
"Ref": "PYTHON37D3A10E04"
}
}
}
}
53 changes: 53 additions & 0 deletions packages/@aws-cdk/aws-lambda/test/integ.runtime.inlinecode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { App, CfnOutput, Stack } from '@aws-cdk/core';
import { Function, InlineCode, Runtime } from '../lib';

// CloudFormation supports InlineCode only for a subset of runtimes. This integration test
// is used to verify that the ones marked in the CDK are in fact supported by CloudFormation.
// Running `cdk deploy` on this stack will confirm if all the runtimes here are supported.
//
// To verify that the lambda function works correctly, use the function names that are part
// of the stack output (printed on the console at the end of 'cdk deploy') and run the command -
// aws lambda invoke --function-name <function-name>
//
// If successful, the output will contain "success"

const app = new App();

const stack = new Stack(app, 'aws-cdk-lambda-runtime-inlinecode');

const node10xfn = new Function(stack, 'NODEJS_10_X', {
code: new InlineCode('exports.handler = async function(event) { return "success" }'),
handler: 'index.handler',
runtime: Runtime.NODEJS_10_X,
});
new CfnOutput(stack, 'NODEJS_10_X-functionName', { value: node10xfn.functionName });

const node12xfn = new Function(stack, 'NODEJS_12_X', {
code: new InlineCode('exports.handler = async function(event) { return "success" }'),
handler: 'index.handler',
runtime: Runtime.NODEJS_12_X,
});
new CfnOutput(stack, 'NODEJS_12_X-functionName', { value: node12xfn.functionName });

const python27 = new Function(stack, 'PYTHON_2_7', {
code: new InlineCode('def handler(event, context):\n return "success"'),
handler: 'index.handler',
runtime: Runtime.PYTHON_2_7,
});
new CfnOutput(stack, 'PYTHON_2_7-functionName', { value: python27.functionName });

const python36 = new Function(stack, 'PYTHON_3_6', {
code: new InlineCode('def handler(event, context):\n return "success"'),
handler: 'index.handler',
runtime: Runtime.PYTHON_3_6,
});
new CfnOutput(stack, 'PYTHON_3_6-functionName', { value: python36.functionName });

const python37 = new Function(stack, 'PYTHON_3_7', {
code: new InlineCode('def handler(event, context):\n return "success"'),
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
});
new CfnOutput(stack, 'PYTHON_3_7-functionName', { value: python37.functionName });

app.synth();

0 comments on commit a1cd743

Please sign in to comment.