Skip to content

Commit f7469c1

Browse files
author
Sam Goodwin
authored
feat(lambda): reserved concurrent executions (#1560)
feat(lambda): reserved concurrent executions
1 parent 3270b47 commit f7469c1

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

packages/@aws-cdk/aws-lambda/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,18 @@ const fn = new lambda.Function(this, 'MyFunction', {
138138
```
139139
See [the AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html)
140140
to learn more about AWS Lambda's X-Ray support.
141+
142+
### Lambda with Reserved Concurrent Executions
143+
144+
```ts
145+
import lambda = require('@aws-cdk/aws-lambda');
146+
147+
const fn = new lambda.Function(this, 'MyFunction', {
148+
runtime: lambda.Runtime.NodeJS810,
149+
handler: 'index.handler',
150+
code: lambda.Code.inline('exports.handler = function(event, ctx, cb) { return cb(null, "hi"); }'),
151+
reservedConcurrentExecutions: 100
152+
});
153+
```
154+
See [the AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html)
155+
managing concurrency.

packages/@aws-cdk/aws-lambda/lib/lambda.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ export interface FunctionProps {
172172
* @default undefined X-Ray tracing disabled
173173
*/
174174
tracing?: Tracing;
175+
176+
/**
177+
* The maximum of concurrent executions you want to reserve for the function.
178+
*
179+
* @default no specific limit - account limit
180+
* @see https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html
181+
*/
182+
reservedConcurrentExecutions?: number;
175183
}
176184

177185
/**
@@ -339,7 +347,8 @@ export class Function extends FunctionBase {
339347
memorySize: props.memorySize,
340348
vpcConfig: this.configureVpc(props),
341349
deadLetterConfig: this.buildDeadLetterConfig(props),
342-
tracingConfig: this.buildTracingConfig(props)
350+
tracingConfig: this.buildTracingConfig(props),
351+
reservedConcurrentExecutions: props.reservedConcurrentExecutions
343352
});
344353

345354
resource.addDependency(this.role);

packages/@aws-cdk/aws-lambda/test/test.lambda.ts

+36
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,42 @@ export = {
11151115
Runtime: 'ruby2.5' },
11161116
DependsOn: [ 'MyLambdaServiceRole4539ECB6' ] } } });
11171117
test.done();
1118+
},
1119+
'support reserved concurrent executions'(test: Test) {
1120+
const stack = new cdk.Stack();
1121+
1122+
new lambda.Function(stack, 'MyLambda', {
1123+
code: new lambda.InlineCode('foo'),
1124+
handler: 'index.handler',
1125+
runtime: lambda.Runtime.NodeJS,
1126+
reservedConcurrentExecutions: 10
1127+
});
1128+
1129+
expect(stack).toMatch({ Resources:
1130+
{ MyLambdaServiceRole4539ECB6:
1131+
{ Type: 'AWS::IAM::Role',
1132+
Properties:
1133+
{ AssumeRolePolicyDocument:
1134+
{ Statement:
1135+
[ { Action: 'sts:AssumeRole',
1136+
Effect: 'Allow',
1137+
Principal: { Service: 'lambda.amazonaws.com' } } ],
1138+
Version: '2012-10-17' },
1139+
ManagedPolicyArns:
1140+
// arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
1141+
// tslint:disable-next-line:max-line-length
1142+
[{'Fn::Join': ['', ['arn:', {Ref: 'AWS::Partition'}, ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole']]}],
1143+
}},
1144+
MyLambdaCCE802FB:
1145+
{ Type: 'AWS::Lambda::Function',
1146+
Properties:
1147+
{ Code: { ZipFile: 'foo' },
1148+
Handler: 'index.handler',
1149+
ReservedConcurrentExecutions: 10,
1150+
Role: { 'Fn::GetAtt': [ 'MyLambdaServiceRole4539ECB6', 'Arn' ] },
1151+
Runtime: 'nodejs' },
1152+
DependsOn: [ 'MyLambdaServiceRole4539ECB6' ] } } });
1153+
test.done();
11181154
}
11191155
};
11201156

0 commit comments

Comments
 (0)