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

[apigateway] Cannot call UsagePlan.addApiKey multiple times. #4860

Closed
igilham opened this issue Nov 5, 2019 · 1 comment · Fixed by #4903
Closed

[apigateway] Cannot call UsagePlan.addApiKey multiple times. #4860

igilham opened this issue Nov 5, 2019 · 1 comment · Fixed by #4903
Assignees
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug.

Comments

@igilham
Copy link
Contributor

igilham commented Nov 5, 2019

It appears to be impossible to add multiple API keys to a usage plan in the API Gateway module. Adding a single key works fine, but there is a construct naming conflict when adding multiple keys.

Reproduction Steps

// const api: apigateway.RestApi = new RestApi()....;

const plan = api.addUsagePlan('DefaultUsagePlan', {
    description: `Default usage plan for ${api.node.id}`,
    name: 'DefaultUsagePlan'
});
plan.addApiKey(api.addApiKey('ClientKey'));
plan.addApiKey(api.addApiKey('TestingKey'));

Error Log

When adding a second API key, I get an error complaining about the reuse of a construct name in CDK.

There is already a Construct with name 'UsagePlanKeyResource' in UsagePlan [DefaultUsagePlan]

.../infrastructure/node_modules/@aws-cdk/core/lib/construct.ts:48
        throw new Error(`Validation failed with the following errors:\n  ${errorList}`);
              ^
Error: Validation failed with the following errors:
  [LambdaStack/BotAudioVideoApi] The REST API doesn't contain any methods
    at Function.synth (.../infrastructure/node_modules/@aws-cdk/core/lib/construct.ts:48:15)
    at App.synth (.../infrastructure/node_modules/@aws-cdk/core/lib/app.ts:142:36)
    at process.App.process.once (.../infrastructure/node_modules/@aws-cdk/core/lib/app.ts:121:45)
    at Object.onceWrapper (events.js:286:20)
    at process.emit (events.js:198:13)
    at process.EventEmitter.emit (domain.js:448:20)
    at process.emit (.../infrastructure/node_modules/source-map-support/source-map-support.js:465:21)
    at process.topLevelDomainCallback (domain.js:126:23)

Environment

  • CLI Version : 1.12.0, 1.15.0
  • Framework Version: 1.12.0, 1.15.0
  • OS : MacOS
  • Language : Typescript

Other

I initially tried this using CDK v1.12.0. I have reproduced it in CDK v1.15.0.

There is a work-around using CfnUsagePlanKey:

// const api: apigateway.RestApi = new RestApi()....;

const clientKey = api.addApiKey('ClientKey');
const testingKey = api.addApiKey('TestingKey')
const clientUsagePlanKey = new apiGateway.CfnUsagePlanKey(this, 'ClientUsagePlanKey', {
    keyId: clientKey.keyId,
    keyType: 'API_KEY',
    usagePlanId: plan.usagePlanId
});
const testingUsagePlanKey = new apiGateway.CfnUsagePlanKey(this, 'TestingUsagePlanKey', {
    keyId: testingKey.keyId,
    keyType: 'API_KEY',
    usagePlanId: plan.usagePlanId
});

This is 🐛 Bug Report

@igilham igilham added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 5, 2019
@SomayaB SomayaB added the @aws-cdk/aws-apigateway Related to Amazon API Gateway label Nov 5, 2019
@nija-at nija-at removed the needs-triage This issue or PR still needs to be triaged. label Nov 7, 2019
@nija-at
Copy link
Contributor

nija-at commented Nov 7, 2019

Fix - #4903

@mergify mergify bot closed this as completed in #4903 Nov 8, 2019
mergify bot pushed a commit that referenced this issue Nov 8, 2019
* fix(apigateway): allow multiple api keys to the same usage plan

fixes #4860

* Updated to not change physical ids on existing UsagePlanKey

* Changed to use uniqueId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants