In the CDK documentation, it is mentioned that an external usage plan can be imported using the static function called fromUsagePlanId
. However, this returns an IUsagePlan interface
which does not contain the method addApiStage
to attach my API and its stage.
Here is a snippet of my code:
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
export class CdkApiGwTemplateStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const api = new apigateway.RestApi(this,`${domain.toLowerCase()}-${subDomain.toLowerCase()}`,{
restApiName: `${domain.toLowerCase()}-${subDomain.toLowerCase()}`,
description: apiDescription,
binaryMediaTypes: binaryMediaTypes,
deployOptions: {
accessLogDestination: new LogGroupLogDestination(logGroup),
loggingLevel: cloudwatchLoggingLevel.toUpperCase() as MethodLoggingLevel,
stageName: environment.toLowerCase(),
variables: variables,
},
});
const key = api.addApiKey('ApiKey', {
apiKeyName: apikeyName,
description: apiKeyDescription,
});
const plan = apigateway.UsagePlan.fromUsagePlanId(this, 'getExternalUsagePlan', usagePlanId);
plan.addApiKey(key);
I have tried searching for a CloudFormation level 1 construct to achieve this, but without success. Is there a way to use the addApiStage
method of the UsagePlan
constructor with the IUsagePlan interface
, or any other idea on how to add my API to an existing Usage Plan?