aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.63k stars 3.91k forks source link

(api-gateway): Support SpecRestApi for UsagePlan #22222

Open CaerusKaru opened 2 years ago

CaerusKaru commented 2 years ago

Describe the feature

Currently, when you use a UsagePlan L2 construct, you must specify a Method L2 construct to assign to the throttling-per-method configuration. Unfortunately, if you use a SpecRestApi with a Swagger/OpenAPI definition, there is no L2 Method construct to link to. It would be very helpful if you could initialize a skeleton Method instance for this purpose, or even better, have better processing of the Swagger template so that you could add the usage plan on a method after initialization.

Use Case

Working with Swagger/OpenAPI and needing to initialize a UsagePlan for the API.

Proposed Solution

Something like:

const api = new SpecRestApi(this, 'API', {
  apiDefinition: ApiDefinition.fromInline('...'),
});

const usagePlan = this.api.addUsagePlan('UsagePlan', {...});
usagePlan.addApiStage({
  api,
  throttle: [Method.fromSwagger('my-method')],
});

or

const api = new SpecRestApi(this, 'API', {
  apiDefinition: ApiDefinition.fromInline('...'),
});

// Precondition: we know this API returns special "Swagger" UsagePlan instance
const usagePlan = this.api.addUsagePlan('UsagePlan', {...});
usagePlan.addRule({
    api,
    method: 'my-method', // this then searches and validates the existing config
});

Other Information

No response

Acknowledgements

CDK version used

2.42.0

Environment details (OS name and version, etc.)

macOS 12.6

CaerusKaru commented 2 years ago

cc @rix0rrr we're looking at this for internal Swagger use cases, which primarily target OpenAPI implementations

CaerusKaru commented 2 years ago

Also feels like I should get a prize for the issue number 😄

peterwoodworth commented 2 years ago

Thanks for the request @CaerusKaru, based on what CloudFormation requires I don't see why we shouldn't be able to support this

I am marking this issue as p2, which means that we are unable to work on this immediately.

We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization.

Check out our contributing guide if you're interested in contributing yourself - there's a low chance the team will be able to address this soon but we'd be happy to review a PR 🙂