Skip to content

Commit

Permalink
fix(custom-resources): increase and expose timeout for AwsCustomResou…
Browse files Browse the repository at this point in the history
…rce (#4623)

* fix(custom-resources): increase and expose timeout for AwsCustomResource

Default timeout is now 6 seconds.

Closes #3272

* change default to 30s
  • Loading branch information
jogold authored and mergify[bot] committed Oct 23, 2019
1 parent 8b598c4 commit f17f809
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/@aws-cdk/custom-resources/lib/aws-custom-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ export interface AwsCustomResourceProps {
* @default extract the permissions from the calls
*/
readonly policyStatements?: iam.PolicyStatement[];

/**
* The timeout for the Lambda function implementing this custom resource.
*
* @default Duration.seconds(30)
*/
readonly timeout?: cdk.Duration
}

export class AwsCustomResource extends cdk.Construct {
Expand All @@ -147,7 +154,8 @@ export class AwsCustomResource extends cdk.Construct {
runtime: lambda.Runtime.NODEJS_10_X,
handler: 'index.handler',
uuid: '679f53fa-c002-430c-b0da-5b7982bd2287',
lambdaPurpose: 'AWS'
lambdaPurpose: 'AWS',
timeout: props.timeout || cdk.Duration.seconds(30),
});

if (props.policyStatements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
"Arn"
]
},
"Runtime": "nodejs10.x"
"Runtime": "nodejs10.x",
"Timeout": 30
},
"DependsOn": [
"AWS679f53fac002430cb0da5b7982bd2287ServiceRoleDefaultPolicyD28E1A5E",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,47 @@ export = {

test.done();
},

'timeout defaults to 30 seconds'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: 'id'
}
});

// THEN
expect(stack).to(haveResource('AWS::Lambda::Function', {
Timeout: 30
}));

test.done();
},

'can specify timeout'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: 'id'
},
timeout: cdk.Duration.minutes(15)
});

// THEN
expect(stack).to(haveResource('AWS::Lambda::Function', {
Timeout: 900
}));

test.done();
}
};

0 comments on commit f17f809

Please sign in to comment.