Replies: 2 comments 3 replies
-
This seems to be a limitation of the AWS APIs, maybe not strictly a CDK thing. There aren't L1 constructs for associating an existing usage plan to a api stage. Only for creating the usage plan and associating it all together. I think my scenario is similar, but the dependecies are inverted. I have a separate Infrastructure stack which defines my VPC, and I'd like the add the usage plan to this stack. I can then template out my Application stack, and run that stack multiple times for different environments. I want to share that usage plan across these Application stacks. I can use the usagePlanId along with: var usagePlan = APIGW.UsagePlan.FromUsagePlanId(this, "UsagePlan", props.UsagePlanId); but then usagePlan.AddApiStage(new UsagePlanPerApiStage
{
Api = props.Api,
Stage = props.Api.DeploymentStage
}); |
Beta Was this translation helpful? Give feedback.
-
Initially I was creating my usage plan and api key in the same stack where my rest api is created. Stage deployment happens in other stack, so I was trying to find a way to link my usage plan created from my api stack but from my stage deployment stack. export class ApiDeploymentStack extends Stack {
constructor(scope: App, id: string, props: ApiDeploymentStackProps /* custom StackProps interface */) {
super(scope, id, props as _StackProps /* cast custom props to original cdk StackProps interface */);
const apiId = StringParameter.fromStringParameterName(this, "apiIdSSM", props.ssm.apiId).stringValue;
const api = RestApi.fromRestApiId(this, "apiId", apiId);
// Deployment
const deployment = new Deployment(this, "apiDeployment", {
api,
retainDeployments: true,
});
// Stage
const stage = new Stage(this, "apiStage", {
deployment,
stageName: "v1",
metricsEnabled: true,
tracingEnabled: true,
dataTraceEnabled: true,
loggingLevel: MethodLoggingLevel.INFO,
});
// Api Key
const apiKey = new ApiKey(this, "ApiKey", {
apiKeyName: "api-key",
});
// Usage Plan
const usagePlan = new UsagePlan(this, "UsagePlan", {
name: "usage-plan",
apiStages: [{
api,
stage,
}],
});
usagePlan.addApiKey(apiKey);
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the feature
How to attach an existing usage plan to an api gateway using CDK
Use Case
Cx wants to import existing usagePlan for aws-api-gateway using CDK, but running into this error below:
Resource handler returned message: "Invalid API Stage {api: %s, stage: %s} specified for usageplan %s (Service: ApiGateway, Status Code: 400, Request ID: ...)" (RequestToken: ..., HandlerErrorCode: InvalidRequest)
Proposed Solution
Tried to create new usagePlan from the link here : https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-apigateway.UsagePlan.htmlbut same error occurred. I have included the code snippet
Other Information
Acknowledgements
CDK version used
2.46.0
Environment details (OS name and version, etc.)
Windows
Beta Was this translation helpful? Give feedback.
All reactions