'aws api-gateway - cdk stage deployment setup - updating without drift

I want to setup an api gateway using cdk - with RestApi, Resource, Method and Stage - all included in the cdk stack.

To create the Stage construct in the cdk stack, it required a Deployment, so I defined this in the cdk stack.

deployment = apigateway_v1.Deployment(self, "Deployment", api=rest_api)

stage = apigateway_v1.Stage(
    self, 
    "test",
    deployment=deployment,
    stage_name="test"
)

However, when I later make a change to the Resource Method definition - and re-deploy the cdk stack, the api-gateway is not updating. So I end up either redeploying the api-gateway either via the aws console or the aws-cli create-deployment

But now when I check for cloudformation stack drift, it shows the Stage has drifted.

How can I prevent stack drift while keeping the Stage in the cdk stack?



Solution 1:[1]

Found some suggestion to add a unique identifier to the deployment construct id from the following links:

https://github.com/aws/aws-cdk/issues/13134 https://stackoverflow.com/a/66377831/1211547

a disadvantage is the deployment will be recreated with every cdk deploy even if there are no changes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 indybee