Skip to content

Commit

Permalink
fix(lambda): erroneous inline code support for ruby (#6365)
Browse files Browse the repository at this point in the history
See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-zipfile

fixes #6302



----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*

<!-- 
Please read the contribution guidelines and follow the pull-request checklist:
https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md
 -->
  • Loading branch information
nija-at authored Feb 20, 2020
1 parent ad96bcd commit 8e21e78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 50 deletions.
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 @@ -47,7 +47,7 @@ export class Runtime {
public static readonly DOTNET_CORE_2 = new Runtime('dotnetcore2.0', RuntimeFamily.DOTNET_CORE);
public static readonly DOTNET_CORE_2_1 = new Runtime('dotnetcore2.1', RuntimeFamily.DOTNET_CORE);
public static readonly GO_1_X = new Runtime('go1.x', RuntimeFamily.GO);
public static readonly RUBY_2_5 = new Runtime('ruby2.5', RuntimeFamily.RUBY, { supportsInlineCode: true });
public static readonly RUBY_2_5 = new Runtime('ruby2.5', RuntimeFamily.RUBY);
public static readonly PROVIDED = new Runtime('provided', RuntimeFamily.OTHER);

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-lambda/test/test.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,14 @@ export = testCase({

test.done();
},

'fails when inline code is specified on an incompatible runtime'(test: Test) {
const stack = new cdk.Stack();
test.throws(() => new lambda.Function(stack, 'fn', {
handler: 'foo',
runtime: lambda.Runtime.PROVIDED,
code: lambda.Code.fromInline('foo')
}), /Inline source not allowed for/);
test.done();
}
});
49 changes: 0 additions & 49 deletions packages/@aws-cdk/aws-lambda/test/test.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,55 +1181,6 @@ export = {
test.same(bindTarget, fn);
test.done();
},
'support inline code for Ruby runtime'(test: Test) {
const stack = new cdk.Stack();

new lambda.Function(stack, 'MyLambda', {
code: new lambda.InlineCode('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.RUBY_2_5,
});

expect(stack).toMatch({
Resources:
{
MyLambdaServiceRole4539ECB6:
{
Type: 'AWS::IAM::Role',
Properties:
{
AssumeRolePolicyDocument:
{
Statement:
[{
Action: 'sts:AssumeRole',
Effect: 'Allow',
Principal: { Service: "lambda.amazonaws.com" }
}],
Version: '2012-10-17'
},
ManagedPolicyArns:
// arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
// tslint:disable-next-line:max-line-length
[{ 'Fn::Join': ['', ['arn:', { Ref: 'AWS::Partition' }, ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole']] }],
}
},
MyLambdaCCE802FB:
{
Type: 'AWS::Lambda::Function',
Properties:
{
Code: { ZipFile: 'foo' },
Handler: 'index.handler',
Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] },
Runtime: 'ruby2.5'
},
DependsOn: ['MyLambdaServiceRole4539ECB6']
}
}
});
test.done();
},

'using an incompatible layer'(test: Test) {
// GIVEN
Expand Down

0 comments on commit 8e21e78

Please sign in to comment.