fix(apigatewayv2): allow an idempotent override-id tag on UpdateApi (#4602)

* fix(apigatewayv2): allow an idempotent override-id tag on UpdateApi

A CloudFormation update resends the template's full tag set, so an
AWS::ApiGatewayV2::Api that pinned its id with floci:override-id failed
every stack update with "Reserved tag key floci:override-id can only be
supplied during resource creation" and rolled back.

UpdateApi now passes the api id to the reserved-tag guard, which already
treats an override equal to the existing id as a no-op (as TagResource
does since #3430), and stores the tags with the override keys stripped.
A different override value is still rejected.

docs/services/api-gateway.md now says a changed override is rejected on
TagResource and UpdateApi while resending the current id is accepted.
The TagResource half has been true since #3430 but was never documented.
CloudFormationIntegrationTest covers a stack update that resends the
pinned id and one that changes it.

* fix(apigatewayv2): validate UpdateApi tags before applying any field

UpdateApi set the name, description and other fields before the
reserved-tag guard ran, so a request it rejected had already changed the
stored API. A CloudFormation update that changed an api's override id
rolled back with the stack reporting UPDATE_ROLLBACK_COMPLETE while the
api kept the rejected update's description.

The guard now runs first, so a rejected update leaves the api as it was.
The CloudFormation test checks the description and tags after the
rollback.
This commit is contained in:
Michał Łomnicki authored and GitHub committed 2026-10-01 19:54:15 -04:00
1 parent 955264cf5d
commit cbc4cf9b91
3 files changed
+101 -6

No files matched your search

@@ -1649,6 +1649,97 @@ class CloudFormationIntegrationTest {
.body("Tags.find { it.TagKey == 'floci:override-id' }", nullValue());
}
@Test
void updateStack_httpApiWithOverrideTagKeepsPinnedId() {
String template = """
{
"Resources": {
"MyApi": {
"Type": "AWS::ApiGatewayV2::Api",
"Properties": {
"Name": "cfn-override-api",
"ProtocolType": "HTTP",
"Description": "%s",
"Tags": {
"floci:override-id": "cfn-pinned-api",
"env": "test"
}
}
}
}
}
""";
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateStack")
.formParam("StackName", "cfn-http-api-override-stack")
.formParam("TemplateBody", template.formatted("before"))
.when()
.post("/")
.then()
.statusCode(200);
// Infrastructure tools resend the full tag set, override included, on every update.
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "UpdateStack")
.formParam("StackName", "cfn-http-api-override-stack")
.formParam("TemplateBody", template.formatted("after"))
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
.formParam("StackName", "cfn-http-api-override-stack")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"));
given()
.when()
.get("/v2/apis/cfn-pinned-api")
.then()
.statusCode(200)
.body("description", equalTo("after"))
.body("tags.env", equalTo("test"))
.body("tags.'floci:override-id'", nullValue());
// A different override would rename the API, which is still refused after creation.
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "UpdateStack")
.formParam("StackName", "cfn-http-api-override-stack")
.formParam("TemplateBody", template.formatted("renamed").replace("cfn-pinned-api", "cfn-renamed-api"))
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStacks")
.formParam("StackName", "cfn-http-api-override-stack")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<StackStatus>UPDATE_ROLLBACK_COMPLETE</StackStatus>"));
given()
.when()
.get("/v2/apis/cfn-pinned-api")
.then()
.statusCode(200)
.body("description", equalTo("after"))
.body("tags.env", equalTo("test"));
}
@Test
void createStack_lambdaWithEnvironmentVariables() {
String template = """