-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lambda): allow inline code for nodejs12.x runtime (#5710)
* 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
1 parent
8c43425
commit a1cd743
Showing
3 changed files
with
335 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
281 changes: 281 additions & 0 deletions
281
packages/@aws-cdk/aws-lambda/test/integ.runtime.inlinecode.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
packages/@aws-cdk/aws-lambda/test/integ.runtime.inlinecode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |