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

fix: Handle custom stage name when creating a Usage Plan (#12349) #12350

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ function createUsagePlanResource(that, name) {
ApiStages: [
{
ApiId: that.provider.getApiGatewayRestApiId(),
Stage: that.provider.getStage(),
Stage: that.provider.getApiGatewayStage(),
},
],
Description: `Usage plan "${name}" for ${
that.serverless.service.service
} ${that.provider.getStage()} stage`,
UsagePlanName: `${that.serverless.service.service}-${name}-${that.provider.getStage()}`,
} ${that.provider.getApiGatewayStage()} stage`,
UsagePlanName: `${
that.serverless.service.service
}-${name}-${that.provider.getApiGatewayStage()}`,
},
};
const template = _.cloneDeep(resourceTemplate);
Expand All @@ -26,10 +28,10 @@ function createUsagePlanResource(that, name) {
// create old legacy resources
template.Properties.UsagePlanName = `${
that.serverless.service.service
}-${that.provider.getStage()}`;
}-${that.provider.getApiGatewayStage()}`;
template.Properties.Description = `Usage plan for ${
that.serverless.service.service
} ${that.provider.getStage()} stage`;
} ${that.provider.getApiGatewayStage()} stage`;
// assign quota
if (_.get(usagePlan, 'quota')) {
_.merge(template, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,26 @@ describe('#compileUsagePlan()', () => {
].Properties.ApiStages[0].ApiId
).to.equal('xxxxx');
});

it('should compile custom usage plan resource with custom stage name provided', () => {
awsCompileApigEvents.serverless.service.provider.apiGateway = {
stage: 'custom-stage',
usagePlan: {
throttle: {
burstLimit: 200,
rateLimit: 100,
},
},
};

awsCompileApigEvents.compileUsagePlan();

expect(
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate.Resources[
awsCompileApigEvents.provider.naming.getUsagePlanLogicalId()
].Properties.ApiStages[0].Stage
).to.equal('custom-stage');
});
});

describe('UsagePlan', () => {
Expand Down