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): reserved concurrent executions #1560

Merged
merged 2 commits into from
Jan 17, 2019
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
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-lambda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,18 @@ const fn = new lambda.Function(this, 'MyFunction', {
```
See [the AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html)
to learn more about AWS Lambda's X-Ray support.

### Lambda with Reserved Concurrent Executions

```ts
import lambda = require('@aws-cdk/aws-lambda');

const fn = new lambda.Function(this, 'MyFunction', {
runtime: lambda.Runtime.NodeJS810,
handler: 'index.handler',
code: lambda.Code.inline('exports.handler = function(event, ctx, cb) { return cb(null, "hi"); }'),
reservedConcurrentExecutions: 100
});
```
See [the AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html)
managing concurrency.
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-lambda/lib/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ export interface FunctionProps {
* @default undefined X-Ray tracing disabled
*/
tracing?: Tracing;

/**
* The maximum of concurrent executions you want to reserve for the function.
*
* @default no specific limit - account limit
* @see https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html
*/
reservedConcurrentExecutions?: number;
}

/**
Expand Down Expand Up @@ -339,7 +347,8 @@ export class Function extends FunctionBase {
memorySize: props.memorySize,
vpcConfig: this.configureVpc(props),
deadLetterConfig: this.buildDeadLetterConfig(props),
tracingConfig: this.buildTracingConfig(props)
tracingConfig: this.buildTracingConfig(props),
reservedConcurrentExecutions: props.reservedConcurrentExecutions
});

resource.addDependency(this.role);
Expand Down
36 changes: 36 additions & 0 deletions packages/@aws-cdk/aws-lambda/test/test.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,42 @@ export = {
Runtime: 'ruby2.5' },
DependsOn: [ 'MyLambdaServiceRole4539ECB6' ] } } });
test.done();
},
'support reserved concurrent executions'(test: Test) {
const stack = new cdk.Stack();

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

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',
ReservedConcurrentExecutions: 10,
Role: { 'Fn::GetAtt': [ 'MyLambdaServiceRole4539ECB6', 'Arn' ] },
Runtime: 'nodejs' },
DependsOn: [ 'MyLambdaServiceRole4539ECB6' ] } } });
test.done();
}
};

Expand Down