aws-amplify / aws-amplify/amplify-cli
Unable to attach UsagePlan to ApiStage via CDK
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### Is this feature request related to a new or existing Amplify category?
api
### Is this related to another service?
ApiGateWay, CDK
### Describe the feature you'd like to request
I'd like to use `amplify add custom` to add a usage plan to RESTApi created by Amplify via `amplify add api`.
### Describe the solution you'd like
```
import * as cdk from '@aws-cdk/core';
import * as AmplifyHelpers from '@aws-amplify/cli-extensibility-helper';
import { AmplifyDependentResourcesAttributes } from '../../types/amplify-dependent-resources-ref';
import * as api from '@aws-cdk/aws-apigateway';
export class cdkStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps, amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps) {
super(scope, id, props);
/* Do not remove - Amplify CLI automatically injects the current deployment environment in this input parameter */
const envParameter = new cdk.CfnParameter(this, 'env', {
type: 'String',
description: 'Current Amplify CLI env name',
});
const dependencies: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,
amplifyResourceProps.category,
amplifyResourceProps.resourceName,
[{
category: "api",
resourceName: "apirest"
} ]
);
const restApi = api.RestApi.fromRestApiId(this, 'RestApi', cdk.Fn.ref(dependencies.api.apirest.ApiId));
const usagePlan = new api.UsagePlan(this,'UsagePlan', {
name: "premium",
description: 'Premium Plan'
});
usagePlan.addApiStage({
stage: HOW TO ACCESS STAGE HERE CREATED BY AMPLIFY
}
);
//both restApi.latestDeployment and restApi.deploymentStage are undefined
```
So close yet so far. I am currently not sure if this is a limitation in how CDK works with stages and/or how Amplify creates the Cloudformation template for the Api.
### Describe alternatives you've considered
Using AWS console which creates the potential for the UsagePlan to become detached if the Cloudformation template changes.
Using `amplify/backend/api/apirest/override.ts` directly did not work due to aws-amplify/amplify-category-api#109
### Additional context
_No response_
### Is this something that you'd be interested in working on?
- [ ] 👋 I may be able to implement this feature request
### Would this feature include a breaking change?
- [ ] ⚠️ This feature might incur a breaking change
Contributor guide
Research direction
Start by reproducing the flow with `amplify add api` and `amplify add custom`, then inspect the generated API resources and `amplify/backend/api/apirest/override.ts`. Determine how the Amplify-created stage can be referenced from the CDK `UsagePlan`, and verify that the resulting CloudFormation-managed UsagePlan remains attached after deployment changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- api, cli, cloud
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100