CDK - How to remove API gateway methods with deploy stacks ?

1

Hello,

As stated in the cdk documentation here (https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway-readme.html#breaking-up-methods-and-resources-across-stacks), it is fairly common for REST APIs with a large number of Resources and Methods to hit the CloudFormation limit of 500 resources per stack.

We followed the documentation and implemented NestedStacks as well as a DeployStask. Everything seems to work as expected except that we did not find how to properly remove an API Gateway method.

The deployment.node.addDependency(method) pushes all new or updated methods but we don't know how to deal with deleted methods.

I expected that cdk would try to compute the diff between the methods in the new deployments compared with the last deployment but it does not seem to be the case.

The only workaround we found is to manually redeploy the whole stage from cli or from the console.

How can we remove a method with a deploy stack using cdk only ?

Thanks for your help, Best Regards, Bruno

1개 답변
0

As you already mentioned that for REST APIs with a large number of Resources and Methods which hits the CloudFormation limit of 500 resources per stack, it is suggested to implement nested stacks in order to divide the resources among the multiple child stacks

Now, in order to get the new or updated methods deployed in additon to the deletion of the older or deprecated methods, it is required to update the definition of the cdk application to allow the deletion of the older versions of method deleted during cleanup of the stack resources once the new resources have been deployed successfully.

However, in case these methods have been deleted manually as an out of band change to the cdk application, it is suggested to update the definition of the resource to avoid the drift among the resources. With this, we can ensure that cdk will try to compare the difference between the methods in the new deployments compared with the last deployment.

profile pictureAWS
지원 엔지니어
답변함 2년 전
  • Thank you for your reply.

    I am not sure to understand exactly what you mean by "it is required to update the definition of the cdk application" I understand the remove or deprecated methods can be removed during the cleanup phase.

    Let's take the exemple from the documentation with books and pets API. Let's say I want to remove the books API. I would remove the code regarding BooksStack and I would write new DeployStack(this, { restApiId: restApi.restApiId, methods: petsStack.methods, });

    Then I redeploy. The books method are removed from the resource tab in the aws gateway console but not from the stage tab.

    What do I need to do in addition to update the definition of the cdk application ?

  • +1 to Bruno's question - the proposed answer to this is not explicit enough. Please elaborate.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠