feat(cloudformation): store Tags on AWS::BedrockAgentCore::RuntimeEndpoint (#8510)

The provisioner passes the endpoint's resolved tags to CreateAgentRuntimeEndpoint,
reconciles tag-only changes and removals in place without touching the endpoint
configuration, and restores the prior tags on a failed update and on stack rollback.
The runtime, endpoint and memory reconcile their tags through CfnRollback.reconcileTags.

A failed undo's snapshot is carried onto the restored resource by the new
CfnRollback.carryFailedUndoSnapshot, now shared by AppConfig, AppSync, the REST API,
ELBv2 and Bedrock AgentCore, so ContinueUpdateRollback retries the restore.

The RuntimeEndpoint Tags gap row and the "accepted and not stored" notes are removed.

Closes #7893
This commit is contained in:
Matheus André authored and GitHub committed 2026-11-21 09:18:38 -04:00
1 parent c8304eb002
commit e725ed6e9a
13 files changed
+358 -79

No files matched your search

@@ -233,10 +233,8 @@ public class ApiGatewayRestApiCfnProvisioner implements CfnResourceProvisioner {
*/
@Override
public void mergeFailedUpdateResourceTracking(StackResource previous, StackResource attempted) {
String snapshot = attempted.getAttributes().get(CfnRollback.REST_API_UPDATE_SNAPSHOT_ATTR);
if (REST_API.equals(previous.getResourceType()) && snapshot != null
&& attempted.getAttributes().containsKey(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR)) {
previous.getAttributes().put(CfnRollback.REST_API_UPDATE_SNAPSHOT_ATTR, snapshot);
if (REST_API.equals(previous.getResourceType())) {
CfnRollback.carryFailedUndoSnapshot(previous, attempted, CfnRollback.REST_API_UPDATE_SNAPSHOT_ATTR);
}
}
@@ -421,10 +421,7 @@ public class AppConfigCfnProvisioner implements CfnResourceProvisioner {
*/
@Override
public void mergeFailedUpdateResourceTracking(StackResource previous, StackResource attempted) {
String snapshot = attempted.getAttributes().get(CfnRollback.APPCONFIG_UPDATE_SNAPSHOT_ATTR);
if (snapshot != null && attempted.getAttributes().containsKey(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR)) {
previous.getAttributes().put(CfnRollback.APPCONFIG_UPDATE_SNAPSHOT_ATTR, snapshot);
}
CfnRollback.carryFailedUndoSnapshot(previous, attempted, CfnRollback.APPCONFIG_UPDATE_SNAPSHOT_ATTR);
}
/**
@@ -478,10 +478,7 @@ public class AppSyncCfnProvisioner implements CfnResourceProvisioner {
*/
@Override
public void mergeFailedUpdateResourceTracking(StackResource previous, StackResource attempted) {
String snapshot = attempted.getAttributes().get(CfnRollback.APPSYNC_UPDATE_SNAPSHOT_ATTR);
if (snapshot != null && attempted.getAttributes().containsKey(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR)) {
previous.getAttributes().put(CfnRollback.APPSYNC_UPDATE_SNAPSHOT_ATTR, snapshot);
}
CfnRollback.carryFailedUndoSnapshot(previous, attempted, CfnRollback.APPSYNC_UPDATE_SNAPSHOT_ATTR);
}
@Override
@@ -19,7 +19,6 @@ import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
@@ -63,12 +62,11 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
* Template properties the backing service does not store. The runtime's capacity provider,
* filesystems, hooks, lifecycle, platform version, request-header allowlist and resource
* configurations, and the memory's strategies, indexed keys, namespace keys and stream delivery
* have no representation in the emulated control plane; the endpoint model carries no tags.
* have no representation in the emulated control plane.
*/
private static final Set<String> RUNTIME_NOT_STORED = Set.of("CapacityProviderConfiguration",
"FilesystemConfigurations", "HooksConfiguration", "LifecycleConfiguration", "PlatformVersion",
"RequestHeaderConfiguration", "ResourceConfigurations");
private static final Set<String> RUNTIME_ENDPOINT_NOT_STORED = Set.of("Tags");
private static final Set<String> MEMORY_NOT_STORED = Set.of("IndexedKeys", "MemoryStrategies",
"NamespaceKeys", "StreamDeliveryResources");
private static final Set<String> WARNED_NOT_STORED = ConcurrentHashMap.newKeySet();
@@ -82,8 +80,8 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
/**
* What an in-place update changed on a reused entity, recorded before the change so a stack
* rollback can put it back: the runtime's configuration and tags, the endpoint's target version
* and description, the memory's mutable properties and tags. Internal, like the other
* rollback can put it back: the runtime's configuration and tags, the endpoint's target version,
* description and tags, the memory's mutable properties and tags. Internal, like the other
* {@code __Floci} attributes.
*/
static final String IN_PLACE_PRIOR_ATTR = "__FlociBedrockAgentCorePrior";
@@ -193,13 +191,9 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
}
private void reconcileRuntimeTags(String arn, Map<String, String> desired, String region) {
List<String> stale = ProvisionContext.staleTagKeys(runtimeService.getTagsByArn(region, arn), desired);
if (!stale.isEmpty()) {
runtimeService.untagByArn(region, arn, stale);
}
if (!desired.isEmpty()) {
runtimeService.tagByArn(region, arn, desired);
}
CfnRollback.reconcileTags(runtimeService.getTagsByArn(region, arn).keySet(), desired,
stale -> runtimeService.untagByArn(region, arn, stale),
tags -> runtimeService.tagByArn(region, arn, tags));
}
private void publishRuntime(StackResource r, AgentRuntime runtime, String region) {
@@ -236,7 +230,7 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
String name = required(props, "Name", ctx, RUNTIME_ENDPOINT);
String version = ctx.resolveOrDefault(props, "AgentRuntimeVersion", null);
String description = ctx.resolveOrDefault(props, "Description", null);
warnNotStored(RUNTIME_ENDPOINT, props, RUNTIME_ENDPOINT_NOT_STORED);
Map<String, String> tags = ctx.resolveTags(props, "Tags");
EndpointLocation prior = ctx.isUpdate()
? runtimeService.findEndpointByArn(region, ctx.priorPhysicalId()).orElse(null)
@@ -245,24 +239,33 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
&& name.equals(prior.endpoint().getName())) {
AgentRuntimeEndpoint existing = prior.endpoint();
// An omitted version leaves the endpoint on the version it serves, as UpdateAgentRuntimeEndpoint does.
boolean unchanged = (version == null || version.equals(existing.getTargetVersion()))
&& Objects.equals(description, existing.getDescription());
if (unchanged) {
boolean configurationChanged = !((version == null || version.equals(existing.getTargetVersion()))
&& Objects.equals(description, existing.getDescription()));
String arn = runtimeService.endpointArn(runtimeId, existing, region);
Map<String, String> priorTags = runtimeService.getEndpointTagsByArn(region, arn);
if (!configurationChanged && priorTags.equals(tags)) {
publishRuntimeEndpoint(r, prior.runtime(), existing, region);
return;
}
ObjectNode snapshot = inPlacePrior(runtimeId, region);
ObjectNode endpointPrior = snapshot.putObject("endpoint");
endpointPrior.put("name", name);
endpointPrior.put("targetVersion", existing.getTargetVersion());
endpointPrior.put("description", existing.getDescription());
if (configurationChanged) {
endpointPrior.put("targetVersion", existing.getTargetVersion());
endpointPrior.put("description", existing.getDescription());
}
snapshot.set("tags", MAPPER.valueToTree(priorTags));
writeInPlacePrior(r, snapshot);
CfnRollback.guarded(r, ctx, false, () -> { }, () -> undoInPlace(r),
() -> publishRuntimeEndpoint(r, prior.runtime(),
runtimeService.updateEndpoint(runtimeId, name, version, description, true, region), region));
CfnRollback.guarded(r, ctx, false, () -> { }, () -> undoInPlace(r), () -> {
AgentRuntimeEndpoint endpoint = configurationChanged
? runtimeService.updateEndpoint(runtimeId, name, version, description, true, region)
: existing;
reconcileEndpointTags(arn, tags, region);
publishRuntimeEndpoint(r, prior.runtime(), endpoint, region);
});
} else {
AgentRuntimeEndpoint endpoint = runtimeService.createEndpoint(runtimeId, name, version, description,
null, region);
tags, null, region);
r.setPhysicalId(runtimeService.endpointArn(runtimeId, endpoint, region));
CfnRollback.guarded(r, ctx, true, () -> runtimeService.deleteEndpoint(runtimeId, name, null, region),
() -> undoInPlace(r),
@@ -270,6 +273,12 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
}
}
private void reconcileEndpointTags(String arn, Map<String, String> desired, String region) {
CfnRollback.reconcileTags(runtimeService.getEndpointTagsByArn(region, arn).keySet(), desired,
stale -> runtimeService.untagEndpointByArn(region, arn, stale),
tags -> runtimeService.tagEndpointByArn(region, arn, tags));
}
private void publishRuntimeEndpoint(StackResource r, AgentRuntime runtime, AgentRuntimeEndpoint endpoint,
String region) {
String endpointArn = runtimeService.endpointArn(runtime.getAgentRuntimeId(), endpoint, region);
@@ -333,13 +342,9 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
}
private void reconcileMemoryTags(String arn, Map<String, String> desired, String region) {
List<String> stale = ProvisionContext.staleTagKeys(memoryService.getTagsByArn(region, arn), desired);
if (!stale.isEmpty()) {
memoryService.untagByArn(region, arn, stale);
}
if (!desired.isEmpty()) {
memoryService.tagByArn(region, arn, desired);
}
CfnRollback.reconcileTags(memoryService.getTagsByArn(region, arn).keySet(), desired,
stale -> memoryService.untagByArn(region, arn, stale),
tags -> memoryService.tagByArn(region, arn, tags));
}
private void publishMemory(StackResource r, Memory memory, String region) {
@@ -436,6 +441,17 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
ReplacementCleanup.clear(resource);
}
/**
* Keeps the snapshot of an in-place update whose own undo did not complete. The engine restores
* the previous resource and reports the rollback failure once; with the snapshot of the state
* the update started from, a ContinueUpdateRollback restores that state instead of finding
* nothing to undo.
*/
@Override
public void mergeFailedUpdateResourceTracking(StackResource previous, StackResource attempted) {
CfnRollback.carryFailedUndoSnapshot(previous, attempted, IN_PLACE_PRIOR_ATTR);
}
/**
* A replacement is undone through the cleanup record: the displaced entity was never touched.
* A reused entity the update changed in place is put back from the snapshot taken before the
@@ -485,8 +501,16 @@ public class BedrockAgentCoreCfnProvisioner implements CfnResourceProvisioner {
}
case RUNTIME_ENDPOINT -> {
ObjectNode endpointPrior = (ObjectNode) prior.get("endpoint");
AgentRuntimeEndpoint endpoint = runtimeService.updateEndpoint(entityId, text(endpointPrior, "name"),
text(endpointPrior, "targetVersion"), text(endpointPrior, "description"), true, region);
String endpointName = text(endpointPrior, "name");
// A tag-only change snapshots no configuration, and restoring none leaves LastUpdatedAt alone.
AgentRuntimeEndpoint endpoint = endpointPrior.has("targetVersion")
? runtimeService.updateEndpoint(entityId, endpointName, text(endpointPrior, "targetVersion"),
text(endpointPrior, "description"), true, region)
: runtimeService.getEndpoint(entityId, endpointName, region);
if (prior.has("tags")) {
reconcileEndpointTags(runtimeService.endpointArn(entityId, endpoint, region),
stringMap(prior.get("tags")), region);
}
publishRuntimeEndpoint(resource, runtimeService.getAgentRuntime(entityId, region), endpoint, region);
}
case MEMORY -> {
@@ -495,6 +495,26 @@ public final class CfnRollback {
}
}
/**
* Carries the snapshot of an in-place update whose own undo did not complete onto the previous
* resource the engine restores, for a provisioner's {@code mergeFailedUpdateResourceTracking}:
* with the state the update started from, a ContinueUpdateRollback tries the restore again
* instead of finding nothing to undo. An undo that completed spent its snapshot and left no
* {@link #UPDATE_ROLLBACK_FAILURE_ATTR}, so nothing is carried.
*/
public static void carryFailedUndoSnapshot(StackResource previous, StackResource attempted,
String... snapshotAttrs) {
if (!attempted.getAttributes().containsKey(UPDATE_ROLLBACK_FAILURE_ATTR)) {
return;
}
for (String attr : snapshotAttrs) {
String snapshot = attempted.getAttributes().get(attr);
if (snapshot != null) {
previous.getAttributes().put(attr, snapshot);
}
}
}
/**
* Runs the steps that follow a create or change a reused entity in place. If one of them
* throws, what this provision did is undone before the failure propagates: a created entity is
@@ -184,16 +184,9 @@ public class ElbV2CfnProvisioner implements CfnResourceProvisioner {
*/
@Override
public void mergeFailedUpdateResourceTracking(StackResource previous, StackResource attempted) {
if (!attempted.getAttributes().containsKey(CfnRollback.UPDATE_ROLLBACK_FAILURE_ATTR)) {
return;
}
for (String attr : List.of(CfnRollback.TARGET_GROUP_TARGETS_UPDATE_SNAPSHOT_ATTR,
CfnRollback.LISTENER_CERTIFICATES_UPDATE_SNAPSHOT_ATTR)) {
String snapshot = attempted.getAttributes().get(attr);
if (snapshot != null) {
previous.getAttributes().put(attr, snapshot);
}
}
CfnRollback.carryFailedUndoSnapshot(previous, attempted,
CfnRollback.TARGET_GROUP_TARGETS_UPDATE_SNAPSHOT_ATTR,
CfnRollback.LISTENER_CERTIFICATES_UPDATE_SNAPSHOT_ATTR);
}
/**