fix(apigateway): allow idempotent custom-id tags (#3430)

* fix(apigateway): allow idempotent custom-id tags

* fix(apigatewayv2): allow idempotent custom-id tags
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-09-12 13:09:48 -04:00
1 parent 4471e92a0f
commit eb622254bc
5 files changed
+98 -15

No files matched your search

@@ -5,6 +5,7 @@ import org.apache.commons.lang3.function.TriFunction;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@RegisterForReflection
public final class ReservedTags {
@@ -90,11 +91,27 @@ public final class ReservedTags {
* error code rather than the {@code ValidationException} the shared guard uses.
*/
public static void rejectApiGatewayReservedTagsOnUpdate(Map<String, String> tags) {
rejectApiGatewayReservedTagsOnUpdate(tags, null);
}
/**
* API Gateway resource update guard with an idempotent exception for its two id-override keys.
* Infrastructure tools resend the complete tag set, so an override equal to the resource's
* existing id is a no-op. A different value would attempt to rename the resource and remains
* invalid after creation.
*/
public static void rejectApiGatewayReservedTagsOnUpdate(Map<String, String> tags, String resourceId) {
if (tags == null) {
return;
}
for (String key : tags.keySet()) {
for (Map.Entry<String, String> tag : tags.entrySet()) {
String key = tag.getKey();
if (isReserved(key) || DEPRECATED_API_GATEWAY_CUSTOM_ID_KEY.equals(key)) {
boolean idOverride = OVERRIDE_ID_KEY.equals(key)
|| DEPRECATED_API_GATEWAY_CUSTOM_ID_KEY.equals(key);
if (idOverride && resourceId != null && Objects.equals(tag.getValue(), resourceId)) {
continue;
}
throw new AwsException(
BAD_REQUEST_EXCEPTION,
"Reserved tag key " + key + " can only be supplied during resource creation.",
@@ -2000,9 +2000,9 @@ public class ApiGatewayService {
}
public void tagResource(String region, String apiId, Map<String, String> tags) {
ReservedTags.rejectApiGatewayReservedTagsOnUpdate(tags);
RestApi api = getRestApi(region, apiId);
api.getTags().putAll(tags);
ReservedTags.rejectApiGatewayReservedTagsOnUpdate(tags, apiId);
api.getTags().putAll(ReservedTags.stripApiGatewayReservedTags(tags));
apiStore.put(apiKey(region, apiId), api);
}
@@ -1168,9 +1168,9 @@ public class ApiGatewayV2Service {
}
public void tagResource(String resourceArn, Map<String, String> tags) {
ReservedTags.rejectApiGatewayReservedTagsOnUpdate(tags);
TaggedResource target = parseArn(resourceArn);
if (target.isStage()) {
ReservedTags.rejectApiGatewayReservedTagsOnUpdate(tags);
Stage stage = getStage(target.region(), target.apiId(), target.stageName());
if (tags != null && !tags.isEmpty()) {
if (stage.getTags() == null) {
@@ -1182,11 +1182,12 @@ public class ApiGatewayV2Service {
return;
}
Api api = getApi(target.region(), target.apiId());
ReservedTags.rejectApiGatewayReservedTagsOnUpdate(tags, target.apiId());
if (tags != null && !tags.isEmpty()) {
if (api.getTags() == null) {
api.setTags(new java.util.HashMap<>());
}
api.getTags().putAll(tags);
api.getTags().putAll(ReservedTags.stripApiGatewayReservedTags(tags));
}
apiStore.put(apiKey(target.region(), target.apiId()), api);
}