(apigateway): RestApi not redeploying correctly
See original GitHub issueWhen I change a resource path in a RestApi the old path is not removed from the api stage.
The deploy
option of RestApi should update the stage when a change occur in the api.
Reproduction Steps
The initial stack:
const api: RestApi = new RestApi(this, 'rest-api', {
deploy: true,
deployOptions: {
stageName: 'test-stage'
}
})
const myResource:IResource = api.root.addResource("myResource", {})
myResource.addMethod("GET",
new Integration({
type:IntegrationType.MOCK,
integrationHttpMethod:'ANY'
})
)
The deployed resources:
The stage:
If I change the path of the resource:
const myResource:IResource = api.root.addResource("myResourceChanged", {})
and redeploy the stack
What did you expect to happen?
The expect deployed resources:
The expect stage:
What actually happened?
The new deployed resources:
The new stage:
If I manually redeploy the stage from the console, the /myResource is removed from the stage.
Environment
- **CDK CLI Version :1.103.0 (build bc13a66)
- Framework Version:
- **Node.js Version:v14.13.1
- **OS :Windows 10
- **Language (Version):TypeScript(3.9.7)
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Updates to a REST API that require redeployment
Resource updates require redeploying the API, whereas configuration updates do not. API resources that can be updated are detailed in the following table....
Read more >CloudFormation Does Not Redeploy Your APIG: How To Fix ...
Use the apigateway sdk to delete the stage you want to redeploy. Yes, you read that correctly. Then, create a new deployment and...
Read more >How do I force redeployment of my API Gateway using ...
This is not working anymore. Changing description of AWS::ApiGateway::Deployment resource just updates the deployment's description field and it ...
Read more >The problem of updating the apigateway stage in aws cdk.
It doesn't seem to work properly. The addition and modification of resources, methods seem to work well. However, even if RestApi's method is...
Read more >aws.apigateway.Deployment - Pulumi
To properly capture all REST API configuration in a deployment, this resource ... and will not cause the resource to recreate (redeploy the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
any update on this?
Actually, the problem is a little more tricky than I originally thought.
In order to cause little or no disruption to running applications during stack updates, CloudFormation ensures that resources are first created and/or updated before any resources are deleted.
CDK automatically creates a default
Stage
andDeployment
whenever a RestApi is created. To ensure that theDeployment
is kept in sync with the Rest API definition, the CDK needs to trigger a re-deployment of theDeployment
resource. The CDK achieves this by changing the logical id of theDeployment
resource which triggers a replacement.In effect, when a
Resource
is removed from a RestApi and another added, CloudFormation first creates the newResource
, then creates the newDeployment
for the RestApi (that now contains bothResource
s), then deletes the oldDeployment
and finally deletes the oldResource
. So finally, we end up with aDeployment
resource that contains bothResource
s.I can’t think of an easy way to solve this problem with just the CDK.