mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(bedrock-agentcore): use runtime IDs and endpoint names in ARNs (#8088)
* fix(bedrock-agentcore): use runtime IDs and endpoint names in ARNs Keep runtime ARNs stable across versions and use the parent runtime ID and endpoint name for endpoint ARNs. Update API responses, ARN lookups, tagging dispatch and CloudFormation references together. * fix(bedrock-agentcore): preserve legacy and harness runtime lookups
This commit is contained in:
1 parent
8bdf86420b
commit
f2a0bfce4e
23 files changed
+360
-94
No files matched your search
+1
-1
@@ -12,7 +12,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
class BedrockAgentCoreInvokeIntegrationTest {
|
||||
|
||||
private static final String ARN =
|
||||
"arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/abcdef12-3456-7890-abcd-ef1234567890:1";
|
||||
"arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/test-AbCdEfGhIj";
|
||||
private static final String SESSION_ID = "session-0000000000000000000000000000abc";
|
||||
private static final String SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id";
|
||||
|
||||
|
||||
+34
-1
@@ -8,6 +8,8 @@ import io.restassured.path.json.JsonPath;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@@ -52,9 +54,40 @@ class BedrockAgentCoreInvokeValidateIntegrationTest {
|
||||
@Test
|
||||
void invokeUnknownRuntimeReturns404() {
|
||||
String unknown =
|
||||
"arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/00000000-0000-0000-0000-000000000000:1";
|
||||
"arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/missing-AbCdEfGhIj";
|
||||
given().contentType("application/json").body("{}")
|
||||
.when().post("/runtimes/" + unknown + "/invocations")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void invokeUnknownLegacyRuntimeReturns404() {
|
||||
given().contentType("application/json").body("{}")
|
||||
.post("/runtimes/arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/unknown:1/invocations")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void harnessRuntimeExistsOnlyWhileItsHarnessIsRegistered() {
|
||||
String name = "invoke" + UUID.randomUUID().toString().replace("-", "");
|
||||
JsonPath harness = given().contentType("application/json").body("""
|
||||
{"harnessName":"%s","executionRoleArn":"arn:aws:iam::000000000000:role/harness",
|
||||
"model":{"bedrockModelConfig":{"modelId":"test-model"}}}
|
||||
""".formatted(name)).post("/harnesses").then().statusCode(201).extract().jsonPath();
|
||||
String id = harness.getString("harness.harnessId");
|
||||
String arn = harness.getString("harness.environment.agentCoreRuntimeEnvironment.agentRuntimeArn");
|
||||
cleanup.register(() -> given().delete("/harnesses/" + id));
|
||||
given().contentType("application/json").body("{}").post("/runtimes/" + arn + "/invocations")
|
||||
.then().statusCode(200);
|
||||
given().delete("/harnesses/" + id).then().statusCode(200);
|
||||
given().contentType("application/json").body("{}").post("/runtimes/" + arn + "/invocations")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInventedHarnessRuntimeDoesNotPassValidation() {
|
||||
given().contentType("application/json").body("{}")
|
||||
.post("/runtimes/arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/harness_missing-AbCdEfGhIj/invocations")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -9,8 +9,8 @@ class BedrockAgentCoreArnsTest {
|
||||
|
||||
@Test
|
||||
void resourceDropsTheQualifier() {
|
||||
assertEquals("agent/abc",
|
||||
BedrockAgentCoreArns.resource("arn:aws:bedrock-agentcore:us-east-1:123456789012:agent/abc:7"));
|
||||
assertEquals("runtime/test-AbCdEfGhIj",
|
||||
BedrockAgentCoreArns.resource("arn:aws:bedrock-agentcore:us-east-1:123456789012:runtime/test-AbCdEfGhIj:7"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -22,7 +22,7 @@ class BedrockAgentCoreArnsTest {
|
||||
@Test
|
||||
void resourceIsNullForAnythingThatIsNotAnArn() {
|
||||
assertNull(BedrockAgentCoreArns.resource(null));
|
||||
assertNull(BedrockAgentCoreArns.resource("agent/abc"));
|
||||
assertNull(BedrockAgentCoreArns.resource("runtime/test-AbCdEfGhIj"));
|
||||
assertNull(BedrockAgentCoreArns.resource("arn:aws:bedrock-agentcore:us-east-1"));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -32,7 +32,7 @@ final class BedrockAgentCoreConcurrencyFixture {
|
||||
AgentRuntime runtime = service.createAgentRuntime("probe", artifact, network,
|
||||
"arn:aws:iam::000000000000:role/probe", null, null, null, null, null, REGION);
|
||||
runtimeId = runtime.getAgentRuntimeId();
|
||||
arn = service.arn(runtime, "1", REGION);
|
||||
arn = service.arn(runtime, REGION);
|
||||
}
|
||||
|
||||
AgentRuntime delete() {
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ class BedrockAgentCoreControlIntegrationTest {
|
||||
.body("agentRuntimeVersion", equalTo("1"))
|
||||
.body("status", equalTo("READY"))
|
||||
.body("agentRuntimeArn", containsString(":bedrock-agentcore:"))
|
||||
.body("agentRuntimeArn", containsString(":agent/"))
|
||||
.body("agentRuntimeArn", containsString(":runtime/"))
|
||||
.body("workloadIdentityDetails.workloadIdentityArn", notNullValue())
|
||||
.extract().path("agentRuntimeId");
|
||||
}
|
||||
|
||||
+7
-7
@@ -66,9 +66,9 @@ class BedrockAgentCoreControlServiceTest {
|
||||
assertEquals(1, rt.getLatestVersion());
|
||||
assertEquals("READY", rt.getStatus());
|
||||
assertTrue(rt.getWorkloadIdentityArn().contains(":bedrock-agentcore:"));
|
||||
assertTrue(service.arn(rt, "1", REGION)
|
||||
.matches("arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/[0-9a-f-]{36}:1"),
|
||||
service.arn(rt, "1", REGION));
|
||||
assertTrue(service.arn(rt, REGION)
|
||||
.equals("arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/" + rt.getAgentRuntimeId()),
|
||||
service.arn(rt, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -442,7 +442,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
String id = rt.getAgentRuntimeId();
|
||||
AgentRuntimeEndpoint ep = service.createEndpoint(id, "prod", null, null,
|
||||
Map.of("env", "prod"), null, REGION);
|
||||
String endpointArn = service.endpointArn(ep, REGION);
|
||||
String endpointArn = service.endpointArn(id, ep, REGION);
|
||||
|
||||
assertEquals(Map.of("env", "prod"), service.getEndpointTagsByArn(REGION, endpointArn));
|
||||
|
||||
@@ -451,7 +451,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
|
||||
assertEquals(Map.of("team", "ml"), service.getEndpointTagsByArn(REGION, endpointArn));
|
||||
assertEquals(Map.of("owner", "runtime"),
|
||||
service.getTagsByArn(REGION, service.arn(rt, "1", REGION)));
|
||||
service.getTagsByArn(REGION, service.arn(rt, REGION)));
|
||||
assertTrue(service.getEndpoint(id, "DEFAULT", REGION).getTags().isEmpty());
|
||||
}
|
||||
|
||||
@@ -461,7 +461,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
String id = rt.getAgentRuntimeId();
|
||||
AgentRuntimeEndpoint ep = service.createEndpoint(id, "prod", null, null,
|
||||
Map.of("fixed", "1"), null, REGION);
|
||||
String endpointArn = service.endpointArn(ep, REGION);
|
||||
String endpointArn = service.endpointArn(id, ep, REGION);
|
||||
AtomicInteger inconsistent = new AtomicInteger();
|
||||
try (ExecutorService executor = Executors.newFixedThreadPool(3)) {
|
||||
Future<?> writer = executor.submit(() -> {
|
||||
@@ -503,7 +503,7 @@ class BedrockAgentCoreControlServiceTest {
|
||||
String id = rt.getAgentRuntimeId();
|
||||
AgentRuntimeEndpoint ep = service.createEndpoint(id, "prod", null, null,
|
||||
Map.of("env", "prod"), null, REGION);
|
||||
String endpointArn = service.endpointArn(ep, REGION);
|
||||
String endpointArn = service.endpointArn(id, ep, REGION);
|
||||
|
||||
service.deleteEndpoint(id, "prod", null, REGION);
|
||||
|
||||
|
||||
+3
-3
@@ -51,7 +51,7 @@ class BedrockAgentCoreEndpointIntegrationTest {
|
||||
.body("endpointName", equalTo("prod"))
|
||||
.body("targetVersion", equalTo("1"))
|
||||
.body("status", equalTo("READY"))
|
||||
.body("agentRuntimeEndpointArn", containsString(":agentEndpoint/"));
|
||||
.body("agentRuntimeEndpointArn", containsString("/runtime-endpoint/prod"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,8 +199,8 @@ class BedrockAgentCoreEndpointIntegrationTest {
|
||||
given().when().delete("/tags/" + endpointArn + "?tagKeys=a")
|
||||
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
|
||||
|
||||
String missingRuntimeArn = endpointArn.replaceAll("agentEndpoint/.*", "agent/missing0000-AbCdEfGhIj");
|
||||
String existingRuntimeArn = endpointArn.replaceAll("agentEndpoint/.*", "agent/" + id);
|
||||
String missingRuntimeArn = endpointArn.replaceAll("runtime/.*", "runtime/missing0000-AbCdEfGhIj");
|
||||
String existingRuntimeArn = endpointArn.replaceAll("runtime/.*", "runtime/" + id);
|
||||
for (String runtimeTarget : new String[] {missingRuntimeArn,
|
||||
existingRuntimeArn.replace(":000000000000:", ":222222222222:"),
|
||||
existingRuntimeArn.replace(":us-east-1:", ":eu-west-1:"),
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class BedrockAgentCorePersistenceTest {
|
||||
"arn:aws:iam::000000000000:role/agent", "v2", Map.of("K", "V"), authorizer, null, REGION);
|
||||
svc.createEndpoint(id, "prod", "1", "prod ep", Map.of("stage", "live"), null, REGION);
|
||||
AgentRuntime before = svc.getAgentRuntime(id, REGION);
|
||||
svc.tagByArn(REGION, svc.arn(before, "1", REGION), Map.of("env", "prod"));
|
||||
svc.tagByArn(REGION, svc.arn(before, REGION), Map.of("env", "prod"));
|
||||
before = svc.getAgentRuntime(id, REGION);
|
||||
|
||||
// Write to disk, then reload into a brand-new backend (simulated restart).
|
||||
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
package io.floci.aws.services.bedrockagentcorecontrol;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.services.bedrockagentcorecontrol.model.AgentRuntime;
|
||||
import io.floci.aws.services.bedrockagentcorecontrol.model.AgentRuntimeEndpoint;
|
||||
import io.floci.aws.services.cloudformation.CloudFormationTemplateEngine;
|
||||
import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
import io.floci.aws.services.cloudformation.provisioners.BedrockAgentCoreCfnProvisioner;
|
||||
import io.floci.aws.services.cloudformation.provisioners.ProvisionContext;
|
||||
import io.floci.aws.testing.MutableClock;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class BedrockAgentCoreRuntimeArnTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String PREFIX = "arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final RegionResolver resolver = new RegionResolver(REGION, "000000000000");
|
||||
private final BedrockAgentCoreControlService service = new BedrockAgentCoreControlService(
|
||||
new InMemoryStorage<>(), resolver, null, new MutableClock());
|
||||
|
||||
private ObjectNode artifact() {
|
||||
return mapper.createObjectNode().set("containerConfiguration",
|
||||
mapper.createObjectNode().put("containerUri", "123456789012.dkr.ecr/x:latest"));
|
||||
}
|
||||
|
||||
private ObjectNode network() {
|
||||
return mapper.createObjectNode().put("networkMode", "PUBLIC");
|
||||
}
|
||||
|
||||
private AgentRuntime create(String name) {
|
||||
return service.createAgentRuntime(name, artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", null, null, null, null, null, REGION);
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeArnUsesTheRuntimeIdAndStaysStableAcrossVersions() {
|
||||
AgentRuntime runtime = create("versioned");
|
||||
String expected = PREFIX + runtime.getAgentRuntimeId();
|
||||
assertEquals(expected, service.arn(runtime, REGION));
|
||||
AgentRuntime updated = service.updateAgentRuntime(runtime.getAgentRuntimeId(), artifact(), network(),
|
||||
"arn:aws:iam::000000000000:role/agent", null, null, null, null, REGION);
|
||||
assertEquals(expected, service.arn(updated, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runtimeArnResolvesItsIdAndChecksDeletedRuntimes() {
|
||||
AgentRuntime runtime = create("lookup");
|
||||
String arn = PREFIX + runtime.getAgentRuntimeId();
|
||||
assertEquals(runtime.getAgentRuntimeId(), service.getAgentRuntimeByArn(REGION, arn).getAgentRuntimeId());
|
||||
assertTrue(service.runtimeArnExists(REGION, arn));
|
||||
service.deleteAgentRuntime(runtime.getAgentRuntimeId(), null, REGION);
|
||||
assertFalse(service.runtimeArnExists(REGION, arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingRuntimeArnDoesNotPassTheExistenceCheck() {
|
||||
assertFalse(service.runtimeArnExists(REGION, PREFIX + "missing-AbCdEfGhIj"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointArnIncludesItsParentAndNameIncludingDefault() {
|
||||
AgentRuntime runtime = create("endpoints");
|
||||
AgentRuntimeEndpoint endpoint = service.createEndpoint(runtime.getAgentRuntimeId(), "prod",
|
||||
null, null, null, REGION);
|
||||
assertEquals(PREFIX + runtime.getAgentRuntimeId() + "/runtime-endpoint/prod",
|
||||
service.endpointArn(runtime.getAgentRuntimeId(), endpoint, REGION));
|
||||
AgentRuntimeEndpoint defaultEndpoint = service.getEndpoint(runtime.getAgentRuntimeId(), "DEFAULT", REGION);
|
||||
assertEquals(PREFIX + runtime.getAgentRuntimeId() + "/runtime-endpoint/DEFAULT",
|
||||
service.endpointArn(runtime.getAgentRuntimeId(), defaultEndpoint, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointLookupUsesTheParentWhenNamesRepeat() {
|
||||
AgentRuntime first = create("first");
|
||||
AgentRuntime second = create("second");
|
||||
service.createEndpoint(first.getAgentRuntimeId(), "prod", null, null, null, REGION);
|
||||
service.createEndpoint(second.getAgentRuntimeId(), "prod", null, null, null, REGION);
|
||||
String arn = PREFIX + second.getAgentRuntimeId() + "/runtime-endpoint/prod";
|
||||
BedrockAgentCoreControlService.EndpointLocation located = service.findEndpointByArn(REGION, arn).orElseThrow();
|
||||
assertEquals(second.getAgentRuntimeId(), located.runtime().getAgentRuntimeId());
|
||||
assertEquals("prod", located.endpoint().getName());
|
||||
assertTrue(service.findEndpointByArn("us-west-2", arn).isEmpty());
|
||||
service.deleteEndpoint(second.getAgentRuntimeId(), "prod", null, REGION);
|
||||
assertTrue(service.findEndpointByArn(REGION, arn).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagHandlerDispatchesRuntimeAndNestedEndpointArnsSeparately() {
|
||||
AgentRuntime runtime = create("tagged");
|
||||
service.createEndpoint(runtime.getAgentRuntimeId(), "prod", null, null, null, REGION);
|
||||
String runtimeArn = PREFIX + runtime.getAgentRuntimeId();
|
||||
String endpointArn = runtimeArn + "/runtime-endpoint/prod";
|
||||
BedrockAgentCoreTagHandler handler = new BedrockAgentCoreTagHandler(service,
|
||||
mock(BedrockAgentCoreGatewayService.class), mock(BedrockAgentCoreMemoryService.class),
|
||||
mock(BedrockAgentCoreHarnessRegistry.class), resolver);
|
||||
handler.tagResource(REGION, runtimeArn, Map.of("owner", "runtime"));
|
||||
handler.tagResource(REGION, endpointArn, Map.of("owner", "endpoint"));
|
||||
assertEquals(Map.of("owner", "runtime"), handler.listTags(REGION, runtimeArn));
|
||||
assertEquals(Map.of("owner", "endpoint"), handler.listTags(REGION, endpointArn));
|
||||
handler.untagResource(REGION, endpointArn, List.of("owner"));
|
||||
assertTrue(handler.listTags(REGION, endpointArn).isEmpty());
|
||||
assertEquals(Map.of("owner", "runtime"), handler.listTags(REGION, runtimeArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownLegacyRuntimeDoesNotPassExistenceValidation() {
|
||||
assertFalse(service.runtimeArnExists(REGION,
|
||||
resolver.buildArn("bedrock-agentcore", REGION, "agent/missing-uuid:1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyRuntimeExistenceFollowsItsStoredUuidAndDeletion() {
|
||||
AgentRuntime runtime = create("legacyRuntime");
|
||||
String arn = resolver.buildArn("bedrock-agentcore", REGION, "agent/" + runtime.getUuid() + ":1");
|
||||
assertTrue(service.runtimeArnExists(REGION, arn));
|
||||
service.deleteAgentRuntime(runtime.getAgentRuntimeId(), null, REGION);
|
||||
assertFalse(service.runtimeArnExists(REGION, arn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyRuntimeAndEndpointTagsRemainSeparate() {
|
||||
AgentRuntime runtime = create("legacyTags");
|
||||
AgentRuntimeEndpoint endpoint = service.createEndpoint(runtime.getAgentRuntimeId(), "prod",
|
||||
null, null, null, REGION);
|
||||
String runtimeArn = resolver.buildArn("bedrock-agentcore", REGION, "agent/" + runtime.getUuid() + ":1");
|
||||
String endpointArn = resolver.buildArn("bedrock-agentcore", REGION, "agentEndpoint/" + endpoint.getUuid());
|
||||
BedrockAgentCoreTagHandler handler = new BedrockAgentCoreTagHandler(service,
|
||||
mock(BedrockAgentCoreGatewayService.class), mock(BedrockAgentCoreMemoryService.class),
|
||||
mock(BedrockAgentCoreHarnessRegistry.class), resolver);
|
||||
handler.tagResource(REGION, runtimeArn, Map.of("scope", "runtime"));
|
||||
handler.tagResource(REGION, endpointArn, Map.of("scope", "endpoint"));
|
||||
assertEquals(Map.of("scope", "runtime"), handler.listTags(REGION, runtimeArn));
|
||||
assertEquals(Map.of("scope", "endpoint"), handler.listTags(REGION, endpointArn));
|
||||
assertEquals(runtime.getAgentRuntimeId(), service.getAgentRuntimeByArn(REGION, runtimeArn).getAgentRuntimeId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyEndpointLookupResolvesItsUuidAndDisappearsAfterDeletion() {
|
||||
AgentRuntime runtime = create("legacyLookup");
|
||||
AgentRuntimeEndpoint endpoint = service.createEndpoint(runtime.getAgentRuntimeId(), "prod",
|
||||
null, null, null, REGION);
|
||||
String arn = resolver.buildArn("bedrock-agentcore", REGION, "agentEndpoint/" + endpoint.getUuid());
|
||||
assertEquals(runtime.getAgentRuntimeId(), service.findEndpointByArn(REGION, arn).orElseThrow()
|
||||
.runtime().getAgentRuntimeId());
|
||||
assertTrue(service.findEndpointByArn("us-west-2", arn).isEmpty());
|
||||
service.deleteEndpoint(runtime.getAgentRuntimeId(), "prod", null, REGION);
|
||||
assertTrue(service.findEndpointByArn(REGION, arn).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cloudFormationUpdatesAnEndpointWithAPersistedLegacyPhysicalId() {
|
||||
AgentRuntime runtime = create("legacyUpdate");
|
||||
AgentRuntimeEndpoint endpoint = service.createEndpoint(runtime.getAgentRuntimeId(), "prod",
|
||||
null, "old", null, REGION);
|
||||
String arn = resolver.buildArn("bedrock-agentcore", REGION, "agentEndpoint/" + endpoint.getUuid());
|
||||
StackResource resource = new StackResource();
|
||||
resource.setLogicalId("Endpoint");
|
||||
resource.setResourceType("AWS::BedrockAgentCore::RuntimeEndpoint");
|
||||
resource.setPhysicalId(arn);
|
||||
resource.setAttributes(new HashMap<>());
|
||||
ObjectNode props = mapper.createObjectNode().put("AgentRuntimeId", runtime.getAgentRuntimeId())
|
||||
.put("Name", "prod").put("Description", "new");
|
||||
CloudFormationTemplateEngine engine = CloudFormationTemplateEngine.standalone("000000000000", REGION,
|
||||
"legacy-stack", mapper, value -> value);
|
||||
new BedrockAgentCoreCfnProvisioner(service, mock(BedrockAgentCoreMemoryService.class)).provision(
|
||||
resource, props, new ProvisionContext(engine, REGION, "000000000000", "legacy-stack", arn));
|
||||
assertEquals(service.endpointArn(runtime.getAgentRuntimeId(), endpoint, REGION), resource.getPhysicalId());
|
||||
assertEquals("new", service.getEndpoint(runtime.getAgentRuntimeId(), "prod", REGION).getDescription());
|
||||
assertEquals(2, service.getAgentRuntime(runtime.getAgentRuntimeId(), REGION).getEndpoints().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cloudFormationDeletesAnEndpointWithAPersistedLegacyPhysicalId() {
|
||||
AgentRuntime runtime = create("legacyDelete");
|
||||
AgentRuntimeEndpoint endpoint = service.createEndpoint(runtime.getAgentRuntimeId(), "prod",
|
||||
null, null, null, REGION);
|
||||
String arn = resolver.buildArn("bedrock-agentcore", REGION, "agentEndpoint/" + endpoint.getUuid());
|
||||
new BedrockAgentCoreCfnProvisioner(service, mock(BedrockAgentCoreMemoryService.class))
|
||||
.delete("AWS::BedrockAgentCore::RuntimeEndpoint", arn, REGION);
|
||||
assertThrows(AwsException.class, () -> service.getEndpoint(runtime.getAgentRuntimeId(), "prod", REGION));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,7 @@ class BedrockAgentCoreTagHandlerTest {
|
||||
|
||||
private static String endpointArn(String partition) {
|
||||
return "arn:" + partition + ":bedrock-agentcore:" + CUSTOM_REGION + ":" + ACCOUNT
|
||||
+ ":agentEndpoint/abc123";
|
||||
+ ":runtime/test-AbCdEfGhIj/runtime-endpoint/prod";
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -210,7 +210,7 @@ class CloudFormationBedrockAgentCoreIntegrationTest {
|
||||
String runtimeArn = outputs.get("RuntimeArn");
|
||||
assertEquals(runtimeId, outputs.get("RuntimeRef"));
|
||||
assertTrue(runtimeId.startsWith("cfn_agent_runtime-"), runtimeId);
|
||||
assertTrue(runtimeArn.matches("arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/[0-9a-f-]{36}:1"),
|
||||
assertTrue(runtimeArn.matches("arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/[a-zA-Z][a-zA-Z0-9_]{0,47}-[a-zA-Z0-9]{10}"),
|
||||
runtimeArn);
|
||||
assertEquals("1", outputs.get("RuntimeVersion"));
|
||||
assertEquals("READY", outputs.get("RuntimeStatus"));
|
||||
@@ -219,7 +219,7 @@ class CloudFormationBedrockAgentCoreIntegrationTest {
|
||||
|
||||
String endpointArn = outputs.get("EndpointArn");
|
||||
assertEquals(endpointArn, outputs.get("EndpointRef"));
|
||||
assertTrue(endpointArn.startsWith("arn:aws:bedrock-agentcore:us-east-1:000000000000:agentEndpoint/"), endpointArn);
|
||||
assertEquals(runtimeArn + "/runtime-endpoint/prod", endpointArn);
|
||||
assertEquals(runtimeArn, outputs.get("EndpointRuntimeArn"));
|
||||
assertEquals("1", outputs.get("EndpointTargetVersion"));
|
||||
assertEquals("READY", outputs.get("EndpointStatus"));
|
||||
|
||||
+8
-8
@@ -46,7 +46,7 @@ class BedrockAgentCoreCfnProvisionerTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String RUNTIME_ID = "agent-abcdefghij";
|
||||
private static final String RUNTIME_ARN = "arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/uuid:1";
|
||||
private static final String RUNTIME_ARN = "arn:aws:bedrock-agentcore:us-east-1:000000000000:runtime/" + RUNTIME_ID;
|
||||
private static final String MEMORY_ID = "mem-abcdefghij";
|
||||
private static final String MEMORY_ARN = "arn:aws:bedrock-agentcore:us-east-1:000000000000:memory/" + MEMORY_ID;
|
||||
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/agent";
|
||||
@@ -127,7 +127,7 @@ class BedrockAgentCoreCfnProvisionerTest {
|
||||
void aFnIfSelectingNoValueInsideNetworkConfigurationIsOmitted() {
|
||||
when(runtimes.createAgentRuntime(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(runtime(null, Map.of()));
|
||||
when(runtimes.arn(any(), any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
when(runtimes.arn(any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
ObjectNode props = runtimeProps(mapper, null, "agents");
|
||||
// No condition is defined, so Fn::If takes its else branch, as an undefined condition does.
|
||||
props.set("NetworkConfiguration", json("""
|
||||
@@ -148,7 +148,7 @@ class BedrockAgentCoreCfnProvisionerTest {
|
||||
void aFailedTaggingAfterCreateDeletesTheRuntimeBeforePropagating() {
|
||||
when(runtimes.createAgentRuntime(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()))
|
||||
.thenReturn(runtime(null, Map.of()));
|
||||
when(runtimes.arn(any(), any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
when(runtimes.arn(any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
doThrow(new AwsException("ThrottlingException", "slow down", 429))
|
||||
.when(runtimes).tagByArn(eq(REGION), eq(RUNTIME_ARN), anyMap());
|
||||
StackResource r = resource("AWS::BedrockAgentCore::Runtime");
|
||||
@@ -173,7 +173,7 @@ class BedrockAgentCoreCfnProvisionerTest {
|
||||
endpoint.setCreatedAt(Instant.EPOCH);
|
||||
endpoint.setLastUpdatedAt(Instant.EPOCH);
|
||||
when(runtimes.createEndpoint(RUNTIME_ID, "prod", null, null, null, REGION)).thenReturn(endpoint);
|
||||
when(runtimes.endpointArn(endpoint, REGION)).thenReturn("arn:ep");
|
||||
when(runtimes.endpointArn(RUNTIME_ID, endpoint, REGION)).thenReturn("arn:ep");
|
||||
when(runtimes.getAgentRuntime(RUNTIME_ID, REGION))
|
||||
.thenThrow(new AwsException("InternalServerException", "boom", 500));
|
||||
ObjectNode props = mapper.createObjectNode();
|
||||
@@ -190,7 +190,7 @@ class BedrockAgentCoreCfnProvisionerTest {
|
||||
void rollbackUpdateRestoresAnInPlaceRuntimeChangeAsANewVersion() {
|
||||
AgentRuntime prior = runtime("one", Map.of("K", "v"));
|
||||
when(runtimes.getAgentRuntime(RUNTIME_ID, REGION)).thenReturn(prior);
|
||||
when(runtimes.arn(any(), any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
when(runtimes.arn(any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
when(runtimes.getTagsByArn(REGION, RUNTIME_ARN)).thenReturn(new HashMap<>(Map.of("team", "agents")));
|
||||
when(runtimes.updateAgentRuntime(eq(RUNTIME_ID), any(), any(), any(), any(), any(), any(), any(), eq(REGION)))
|
||||
.thenReturn(prior);
|
||||
@@ -216,7 +216,7 @@ class BedrockAgentCoreCfnProvisionerTest {
|
||||
void anUnchangedRuntimeIsNeitherUpdatedNorSnapshotted() {
|
||||
AgentRuntime prior = runtime("one", Map.of());
|
||||
when(runtimes.getAgentRuntime(RUNTIME_ID, REGION)).thenReturn(prior);
|
||||
when(runtimes.arn(any(), any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
when(runtimes.arn(any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
when(runtimes.getTagsByArn(REGION, RUNTIME_ARN)).thenReturn(new HashMap<>(Map.of("team", "agents")));
|
||||
StackResource r = resource("AWS::BedrockAgentCore::Runtime");
|
||||
r.setPhysicalId(RUNTIME_ID);
|
||||
@@ -271,8 +271,8 @@ class BedrockAgentCoreCfnProvisionerTest {
|
||||
.thenReturn(Optional.of(new BedrockAgentCoreControlService.EndpointLocation(runtime, existing)));
|
||||
when(runtimes.updateEndpoint(eq(RUNTIME_ID), eq("prod"), any(), any(), anyBoolean(), eq(REGION)))
|
||||
.thenReturn(existing);
|
||||
when(runtimes.endpointArn(existing, REGION)).thenReturn("arn:ep");
|
||||
when(runtimes.arn(any(), anyString(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
when(runtimes.endpointArn(RUNTIME_ID, existing, REGION)).thenReturn("arn:ep");
|
||||
when(runtimes.arn(any(), eq(REGION))).thenReturn(RUNTIME_ARN);
|
||||
ObjectNode props = mapper.createObjectNode();
|
||||
props.put("AgentRuntimeId", RUNTIME_ID);
|
||||
props.put("Name", "prod");
|
||||
|
||||
Reference in new issue
Block a user