feat(bedrock-agentcore): keep runtime endpoint create tags and support tagging them (#7597)

This commit is contained in:
Daniël van Ziel authored and GitHub committed 2026-11-06 09:31:50 -04:00
1 parent 0cb45a86df
commit c1a88b8ab8
8 files changed
+305 -8

No files matched your search

@@ -247,8 +247,10 @@ public class BedrockAgentCoreControlController {
String region = regionResolver.resolveRegion(headers);
try {
JsonNode req = objectMapper.readTree(body != null && !body.isBlank() ? body : "{}");
BedrockAgentCoreTagValidation.validateTags(req.get("tags"));
AgentRuntimeEndpoint endpoint = service.createEndpoint(id, text(req, "name"),
text(req, "agentRuntimeVersion"), text(req, "description"), text(req, "clientToken"), region);
text(req, "agentRuntimeVersion"), text(req, "description"), stringMap(req.get("tags")),
text(req, "clientToken"), region);
AgentRuntime runtime = service.getAgentRuntime(id, region);
return Response.status(202).entity(endpointResponse(runtime, endpoint, region, false)).build();
} catch (Exception e) {
@@ -25,6 +25,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer;
import java.util.regex.Pattern;
/**
@@ -341,6 +342,44 @@ public class BedrockAgentCoreControlService {
"AgentCore resource not found: " + arn, 404));
}
public Map<String, String> getEndpointTagsByArn(String region, String arn) {
Map<String, String> snapshot = new HashMap<>();
updateEndpointTags(region, arn, snapshot::putAll, false);
return snapshot;
}
public void tagEndpointByArn(String region, String arn, Map<String, String> tags) {
updateEndpointTags(region, arn, endpointTags -> endpointTags.putAll(tags), true);
}
public void untagEndpointByArn(String region, String arn, List<String> keys) {
updateEndpointTags(region, arn, endpointTags -> keys.forEach(endpointTags::remove), true);
}
private void updateEndpointTags(String region, String arn, Consumer<Map<String, String>> change,
boolean persist) {
EndpointLocation located = requireEndpointByArn(region, arn);
String runtimeId = located.runtime().getAgentRuntimeId();
synchronized (runtimeLock(region, runtimeId)) {
AgentRuntime runtime = getAgentRuntime(runtimeId, region);
AgentRuntimeEndpoint endpoint = runtime.getEndpoints().stream()
.filter(e -> e.getUuid().equals(located.endpoint().getUuid()))
.findFirst()
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"AgentCore resource not found: " + arn, 404));
change.accept(endpoint.getTags());
if (persist) {
storage.put(key(region, runtimeId), runtime);
}
}
}
private EndpointLocation requireEndpointByArn(String region, String arn) {
return findEndpointByArn(region, arn)
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"AgentCore resource not found: " + arn, 404));
}
private static String uuidFromArn(String arn) {
// arn:aws:bedrock-agentcore:<region>:<account>:agent/<uuid>:<version>
String resource = BedrockAgentCoreArns.resource(arn);
@@ -354,6 +393,12 @@ public class BedrockAgentCoreControlService {
public AgentRuntimeEndpoint createEndpoint(String runtimeId, String name, String agentRuntimeVersion,
String description, String clientToken, String region) {
return createEndpoint(runtimeId, name, agentRuntimeVersion, description, null, clientToken, region);
}
public AgentRuntimeEndpoint createEndpoint(String runtimeId, String name, String agentRuntimeVersion,
String description, Map<String, String> tags, String clientToken,
String region) {
synchronized (runtimeLock(region, runtimeId)) {
AgentRuntime runtime = getAgentRuntime(runtimeId, region);
if (clientToken != null) {
@@ -378,6 +423,9 @@ public class BedrockAgentCoreControlService {
requirePublishedVersion(runtime, version);
AgentRuntimeEndpoint endpoint = newEndpoint(name, version, description, Instant.now());
endpoint.setClientToken(clientToken);
if (tags != null) {
endpoint.getTags().putAll(tags);
}
runtime.getEndpoints().add(endpoint);
storage.put(key(region, runtimeId), runtime);
LOG.infov("Created AgentCore endpoint {0} on runtime {1}", name, runtimeId);
@@ -14,7 +14,7 @@ import java.util.Map;
* Tagging for AgentCore resources, dispatched from the shared {@code /tags/{resourceArn}}
* route. All AgentCore resources share the ARN service segment {@code bedrock-agentcore},
* so this handler further dispatches by the resource type in the ARN. AWS supports tagging
* for runtimes, gateways, memories and harnesses.
* for runtimes, runtime endpoints, gateways, memories and harnesses.
*/
@ApplicationScoped
public class BedrockAgentCoreTagHandler implements TagHandler {
@@ -49,6 +49,7 @@ public class BedrockAgentCoreTagHandler implements TagHandler {
case GATEWAY -> gatewayService.getTagsByArn(region, arn);
case MEMORY -> memoryService.getTagsByArn(region, arn);
case RUNTIME -> runtimeService.getTagsByArn(region, arn);
case ENDPOINT -> runtimeService.getEndpointTagsByArn(region, arn);
case HARNESS -> harnessRegistry.getTagsByArn(region, arn);
};
}
@@ -59,6 +60,7 @@ public class BedrockAgentCoreTagHandler implements TagHandler {
case GATEWAY -> gatewayService.tagByArn(region, arn, tags);
case MEMORY -> memoryService.tagByArn(region, arn, tags);
case RUNTIME -> runtimeService.tagByArn(region, arn, tags);
case ENDPOINT -> runtimeService.tagEndpointByArn(region, arn, tags);
case HARNESS -> harnessRegistry.tagByArn(region, arn, tags);
}
}
@@ -69,11 +71,12 @@ public class BedrockAgentCoreTagHandler implements TagHandler {
case GATEWAY -> gatewayService.untagByArn(region, arn, tagKeys);
case MEMORY -> memoryService.untagByArn(region, arn, tagKeys);
case RUNTIME -> runtimeService.untagByArn(region, arn, tagKeys);
case ENDPOINT -> runtimeService.untagEndpointByArn(region, arn, tagKeys);
case HARNESS -> harnessRegistry.untagByArn(region, arn, tagKeys);
}
}
private enum ResourceKind { RUNTIME, GATEWAY, MEMORY, HARNESS }
private enum ResourceKind { RUNTIME, ENDPOINT, GATEWAY, MEMORY, HARNESS }
private ResourceKind kind(String region, String arn) {
String resource = BedrockAgentCoreArns.resource(arn);
@@ -88,6 +91,9 @@ public class BedrockAgentCoreTagHandler implements TagHandler {
if (resource.startsWith("agent/")) {
return ResourceKind.RUNTIME;
}
if (resource.startsWith("agentEndpoint/")) {
return ResourceKind.ENDPOINT;
}
if (resource.startsWith("memory/")) {
return ResourceKind.MEMORY;
}
@@ -100,13 +106,15 @@ public class BedrockAgentCoreTagHandler implements TagHandler {
}
/**
* All four services resolve a resource from the ARN's id suffix alone, so without this a
* caller could reach a local runtime, gateway, memory or harness through an ARN naming another
* account or region and read or change its tags. Reported as not found rather than a
* The runtime, gateway, memory and harness services resolve a resource from the ARN's id
* suffix alone, so without this a caller could reach a local runtime, runtime endpoint,
* gateway, memory or harness through an ARN naming another account, region or partition and
* read or change its tags. Reported as not found rather than a
* validation error, so the response does not confirm what exists behind the foreign identity.
*/
private void requireLocalIdentity(String region, String arn, AwsArnUtils.Arn parsed) {
if (!region.equals(parsed.region()) || !regionResolver.getAccountId().equals(parsed.accountId())) {
if (!regionResolver.partitionForRegion(region).equals(parsed.partition())
|| !region.equals(parsed.region()) || !regionResolver.getAccountId().equals(parsed.accountId())) {
throw new AwsException("ResourceNotFoundException",
"AgentCore resource not found: " + arn, 404);
}
@@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
/**
* A named endpoint (qualifier) pointing at a specific version of an AgentCore Runtime.
@@ -24,6 +26,7 @@ public class AgentRuntimeEndpoint {
private String clientToken;
private Instant createdAt;
private Instant lastUpdatedAt;
private Map<String, String> tags = new HashMap<>();
public String getName() {
return name;
@@ -96,4 +99,12 @@ public class AgentRuntimeEndpoint {
public void setLastUpdatedAt(Instant lastUpdatedAt) {
this.lastUpdatedAt = lastUpdatedAt;
}
public Map<String, String> getTags() {
return tags;
}
public void setTags(Map<String, String> tags) {
this.tags = tags != null ? tags : new HashMap<>();
}
}