Skip to content

Commit

Permalink
fix(apigateway): burst and rate limits are set to unlimited when conf…
Browse files Browse the repository at this point in the history
…igured to 0 (#10088)

Closes #10071 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
cyuste committed Sep 2, 2020
1 parent 61b45f3 commit 96f1772
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ export class UsagePlan extends Resource {
validateInteger(rateLimit, 'Throttle rate limit');

ret = {
burstLimit: burstLimit ? burstLimit : undefined,
rateLimit: rateLimit ? rateLimit : undefined,
burstLimit: burstLimit,
rateLimit: rateLimit,
};
}
return ret!;
Expand Down
56 changes: 55 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.usage-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export = {
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
const usagePlanName = 'Basic';
const usagePlanDescription = 'Basic Usage Plan with no throttling limits';
const usagePlanDescription = 'Basic Usage Plan with throttling limits';

// WHEN
new apigateway.UsagePlan(stack, 'my-usage-plan', {
Expand Down Expand Up @@ -82,6 +82,60 @@ export = {

},

'usage plan with blocked methods'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
const usagePlanName = 'Basic';
const usagePlanDescription = 'Basic Usage Plan with throttling limits';

// WHEN
new apigateway.UsagePlan(stack, 'my-usage-plan', {
name: usagePlanName,
description: usagePlanDescription,
apiStages: [
{
stage: api.deploymentStage,
throttle: [
{
method,
throttle: {
burstLimit: 0,
rateLimit: 0,
},
},
],
},
],
});

// THEN
expect(stack).to(haveResource(RESOURCE_TYPE, {
UsagePlanName: usagePlanName,
Description: usagePlanDescription,
ApiStages: [
{
ApiId: {
Ref: 'myapi4C7BF186',
},
Stage: {
Ref: 'myapiDeploymentStagetest4A4AB65E',
},
Throttle: {
'//GET': {
BurstLimit: 0,
RateLimit: 0,
},
},
},
],
}, ResourcePart.Properties));

test.done();

},

'usage plan with quota limits'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 96f1772

Please sign in to comment.