-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(apigateway): prevent deletion of stages during deployment replacement #13736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(apigateway): prevent deletion of stages during deployment replacement #13736
Conversation
cloutierMat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @shubhiscoding for the contribution and taking the time to add an aws validated test.
I am requesting a few changes on the issue before I can merge as I would rather see a fix to getStages filtering over a patch in the CloudFormation resource providers.
Also in addition to the CFN test you added I would like to see a small test for the filter in tests.aws.services.apigateway.test_apigateway_api. There are currently no tests for the deployment and I don't expect the full CRUD test suite either, but at least a small regression test for the filtering behavior.
Let me know if you need extra guidance or have any questions.
localstack-core/localstack/services/apigateway/resource_providers/aws_apigateway_deployment.py
Outdated
Show resolved
Hide resolved
Forgot to address this..., looking into it...! |
|
Hi @cloutierMat , thanks for the review! I've pushed all the requested changes:
Both tests are validated against AWS! |
cloutierMat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you for the quick response. I only see a couple of minor changes needed to the snapshot transformers. I will be happy to merged once solved.
Btw, no need to worry about the lambda test failure, this is an unrelated flake.
|
|
||
| class TestApiGatewayStage: | ||
| @markers.aws.validated | ||
| def test_get_stages_filters_by_deployment_id(self, aws_client, apigw_create_rest_api, snapshot): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test addition, thank you for adding our first stage CRUD test 🥳
cloutierMat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shubhiscoding In order to save us a day of back and forth (looks like we are in different TZ), I took the liberty to apply the requested changes since they were only minor snapshot transformers adjustments.
Thank you again for you contributions and for quickly resolving the previous comments I made. I will approve and merge this pr and your fix will be available in our next image build.
Thanks @cloutierMat! TZ wasn’t the issue — I just had some office work to handle and was planning to look into it a bit later. thanks for taking care of the changes and for the review too🫡! |
Motivation
When the Serverless Framework redeploys, it generates a new deployment logical ID each time (e.g.,
ApiGatewayDeployment1708076354025→ApiGatewayDeployment1708076563720). CloudFormation treats this as Add(new) + Remove(old).The old deployment's CloudFormation delete handler calls
get_stages(deploymentId=old_id)to find associated stages. However, the underlying implementation does not filter bydeploymentId— it returns all stages regardless. The delete handler then blindly deletes all returned stages, including the stage that was already reassigned to the new deployment.This causes all subsequent API requests (including CORS OPTIONS) to return 404 after a redeploy.
Changes
deploymentIdownership check in theApiGatewayDeploymentProvider.delete()handler: before deleting a stage, verify thatstage.deploymentIdmatches the deployment being deleted. Stages that have been reassigned to a newer deployment are skipped.Tests
test_serverless_like_deployment_stage_survives_updateregression test that:Deploy1000000001) with stagelocalDeploy2000000002), simulating the Serverless Framework redeploy patterntest_apigateway.validation.json)Related
Fixes #13667