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(lambda): allow inline code for nodejs12.x runtime #5710

Merged
merged 6 commits into from Jan 16, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();