mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(bedrockagentcore): emulate the AgentCore control plane and InvokeAgentRuntime stub (#2316)
* docs(bedrockagentcore): add AgentCore emulation design + upgrade path
* feat(bedrockagentcore): add agent runtime CRUD control plane
Implements the bedrock-agentcore-control runtime registry (Phase 1):
Create/Get/List/Update/Delete AgentRuntime plus ListAgentRuntimeVersions,
with immutable version snapshots, cursor pagination, and ISO-8601 timestamps.
- REST-JSON controller + service + reflection-safe models
- ServiceRegistry descriptor + EmulatorConfig toggle
- Unit + RestAssured integration tests
- AWS SDK v2 compatibility test (sdk-test-java)
- Service docs page
Refs lex00/floci#2
* feat(bedrockagentcore): add agent runtime endpoints
Phase 2: Create/Get/Update/Delete/List AgentRuntimeEndpoint under
/runtimes/{id}/runtime-endpoints/, with a DEFAULT endpoint auto-created per
runtime and agentEndpoint/<uuid> ARNs. RestAssured + SDK v2 compat tests.
Refs lex00/floci#3
* feat(bedrockagentcore): add InvokeAgentRuntime data-plane stub
Phase 3: POST /runtimes/{agentRuntimeArn}/invocations returns a fixed,
configurable canned response ({"output":"yes"}) and echoes the runtime
session id. Opaque payload is never parsed; streaming is not emulated.
Separate stateless bedrock-agentcore service. RestAssured + SDK v2 compat tests.
Refs lex00/floci#4
* feat(bedrockagentcore): add tagging and workload identity
Phase 4:
- TagResource/UntagResource/ListTagsForResource for runtime ARNs via a
TagHandler on the shared /tags/{arn} route
- Workload identity RPC CRUD (POST /identities/<Op>); each runtime auto-creates
a resolvable workload identity
- Workload-identity timestamps are epoch-seconds (unixTimestamp), distinct from
the runtime ISO-8601 timestamps
RestAssured + SDK v2 compat tests.
Refs lex00/floci#5
* feat(bedrockagentcore): add gateway and memory primitives
Phase 5 (optional): metadata-only CRUD registries.
- Gateways (POST /gateways/) + gateway targets, standard REST
- Memory (POST /memories/create, GET /memories/{id}/details, ...), action-suffix
- Gateway timestamps are ISO-8601; memory timestamps are epoch seconds
RestAssured + SDK v2 compat tests.
Refs lex00/floci#6
* fix(bedrockagentcore): correctness fixes from adversarial audit
- Fix ListAgentRuntimeVersions pagination cycling for >=10 versions: sort by
the pagination cursor and zero-pad the version cursor (closes #7)
- Capture authorizerConfiguration/protocolConfiguration in version snapshots so
GetAgentRuntime?version returns the requested version's config (closes #8)
- Support tagging AgentCore gateways (AWS-taggable): add tags to Gateway,
dispatch the TagHandler by ARN resource type, store tags on CreateGateway;
non-taggable AgentCore ARNs now 400 (closes #9)
- Validate maxResults range (1..N) across all list operations (closes #12)
Adds regression tests: version-pagination multi-page, version-config snapshot,
gateway tag round-trip (REST + SDK), unsupported-ARN 400, maxResults + malformed
nextToken validation, and an HTTP-level multi-page pagination test.
Refs lex00/floci#14
* feat(bedrockagentcore): clientToken idempotency, invoke existence flag, config docs
- clientToken idempotency for Runtime/Endpoint/Memory create+delete (lenient:
same token returns the existing resource; completed-delete tokens tracked
in-memory so a replayed delete returns 202 not 404) (closes #10)
- InvokeAgentRuntime existence check behind floci.services.bedrock-agent-core
.validate-runtime-exists (default false, preserving permissive behavior);
when on, unknown runtime ARNs return ResourceNotFoundException (closes #11)
- Document that YAML config keys are hyphenated (bedrock-agent-core-control),
distinct from the reported service name (closes #13)
Adds unit tests (create/delete idempotency), a TestProfile integration test for
the existence flag, and an SDK v2 idempotency compat test.
Refs lex00/floci#10 lex00/floci#11 lex00/floci#13
* ci: trigger fork pipeline dry-run
* test(bedrockagentcore): add persistence, region-isolation, concurrency and boundary coverage
Closes the structural test gaps from the audit (issue #14):
- Persistence-across-restart: full AgentRuntime (JsonNode config, Instants,
version snapshots, endpoints, tags, env vars) round-trips through
PersistentStorage to disk and reloads intact
- Region isolation: a runtime is invisible/ungettable from another region
- Concurrency: concurrent creates all persist (no dropped inserts)
- Endpoint version retargeting, gateway + target update, duplicate-name 409,
and memory eventExpiryDuration boundaries (2/3/365/366)
Refs lex00/floci#14
* fix(bedrockagentcore): validate endpoint versions and the identity in a tagging ARN
createEndpoint and updateEndpoint stored agentRuntimeVersion without resolving
it against the runtime, so a version that was never published produced a READY
endpoint whose generated runtime ARN resolves to nothing. Both now reject one
the runtime has not published.
Tag operations resolved a resource from the ARN's id suffix alone, so an ARN
naming another account or region but a local id reached the local runtime or
gateway and could read or change its tags. The shared tag dispatch now checks
both fields against the request, which covers runtimes and gateways in one
place, and reports not found rather than a validation error so the response
does not confirm what sits behind the foreign identity.
This commit is contained in:
1 parent
6b14999974
commit
4e6e6df06d
43 files changed
+5405
No files matched your search
+138
@@ -0,0 +1,138 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.BedrockAgentCoreControlClient;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.model.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Bedrock AgentCore Control")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreControlTest {
|
||||
|
||||
private static final String ACCOUNT_ID = "000000000000";
|
||||
private static final String ROLE_ARN = "arn:aws:iam::" + ACCOUNT_ID + ":role/agent-runtime";
|
||||
|
||||
private static BedrockAgentCoreControlClient client;
|
||||
private static String runtimeName;
|
||||
private static String runtimeId;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
client = TestFixtures.bedrockAgentCoreControlClient();
|
||||
// AgentCore names must match [a-zA-Z][a-zA-Z0-9_]{0,47} — no hyphens.
|
||||
runtimeName = "itAgent" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (client != null) {
|
||||
try {
|
||||
client.deleteAgentRuntime(DeleteAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(runtimeId).build());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static AgentRuntimeArtifact artifact(String uri) {
|
||||
return AgentRuntimeArtifact.builder()
|
||||
.containerConfiguration(ContainerConfiguration.builder().containerUri(uri).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
private static NetworkConfiguration network() {
|
||||
return NetworkConfiguration.builder().networkMode(NetworkMode.PUBLIC).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createAgentRuntime() {
|
||||
CreateAgentRuntimeResponse response = client.createAgentRuntime(CreateAgentRuntimeRequest.builder()
|
||||
.agentRuntimeName(runtimeName)
|
||||
.agentRuntimeArtifact(artifact("public.ecr.aws/x/agent:latest"))
|
||||
.networkConfiguration(network())
|
||||
.roleArn(ROLE_ARN)
|
||||
.description("v1")
|
||||
.build());
|
||||
|
||||
runtimeId = response.agentRuntimeId();
|
||||
assertThat(runtimeId).startsWith(runtimeName + "-");
|
||||
assertThat(response.agentRuntimeVersion()).isEqualTo("1");
|
||||
assertThat(response.statusAsString()).isEqualTo("READY");
|
||||
assertThat(response.agentRuntimeArn()).contains(":bedrock-agentcore:").contains(":agent/");
|
||||
assertThat(response.workloadIdentityDetails().workloadIdentityArn()).isNotBlank();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getAgentRuntime() {
|
||||
GetAgentRuntimeResponse response = client.getAgentRuntime(GetAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(runtimeId).build());
|
||||
|
||||
assertThat(response.agentRuntimeName()).isEqualTo(runtimeName);
|
||||
assertThat(response.agentRuntimeVersion()).isEqualTo("1");
|
||||
assertThat(response.description()).isEqualTo("v1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listAgentRuntimes() {
|
||||
ListAgentRuntimesResponse response = client.listAgentRuntimes(ListAgentRuntimesRequest.builder().build());
|
||||
assertThat(response.agentRuntimes())
|
||||
.anyMatch(r -> runtimeId.equals(r.agentRuntimeId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void updateAgentRuntimeBumpsVersion() {
|
||||
UpdateAgentRuntimeResponse response = client.updateAgentRuntime(UpdateAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(runtimeId)
|
||||
.agentRuntimeArtifact(artifact("public.ecr.aws/x/agent:v2"))
|
||||
.networkConfiguration(network())
|
||||
.roleArn(ROLE_ARN)
|
||||
.description("v2")
|
||||
.build());
|
||||
|
||||
assertThat(response.agentRuntimeVersion()).isEqualTo("2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void getSpecificVersionReturnsSnapshot() {
|
||||
GetAgentRuntimeResponse response = client.getAgentRuntime(GetAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(runtimeId)
|
||||
.agentRuntimeVersion("1")
|
||||
.build());
|
||||
|
||||
assertThat(response.agentRuntimeVersion()).isEqualTo("1");
|
||||
assertThat(response.description()).isEqualTo("v1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deleteAgentRuntime() {
|
||||
DeleteAgentRuntimeResponse response = client.deleteAgentRuntime(DeleteAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(runtimeId).build());
|
||||
assertThat(response.statusAsString()).isEqualTo("DELETING");
|
||||
|
||||
assertThatThrownBy(() -> client.getAgentRuntime(GetAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(runtimeId).build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void createWithInvalidNameThrowsValidation() {
|
||||
assertThatThrownBy(() -> client.createAgentRuntime(CreateAgentRuntimeRequest.builder()
|
||||
.agentRuntimeName("1-invalid-name")
|
||||
.agentRuntimeArtifact(artifact("x:latest"))
|
||||
.networkConfiguration(network())
|
||||
.roleArn(ROLE_ARN)
|
||||
.build()))
|
||||
.isInstanceOf(ValidationException.class);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.BedrockAgentCoreControlClient;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.model.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Bedrock AgentCore Runtime Endpoints")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreEndpointTest {
|
||||
|
||||
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/agent-runtime";
|
||||
|
||||
private static BedrockAgentCoreControlClient client;
|
||||
private static String runtimeId;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
client = TestFixtures.bedrockAgentCoreControlClient();
|
||||
String name = "epAgent" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
runtimeId = client.createAgentRuntime(CreateAgentRuntimeRequest.builder()
|
||||
.agentRuntimeName(name)
|
||||
.agentRuntimeArtifact(AgentRuntimeArtifact.builder()
|
||||
.containerConfiguration(ContainerConfiguration.builder()
|
||||
.containerUri("public.ecr.aws/x/agent:latest").build())
|
||||
.build())
|
||||
.networkConfiguration(NetworkConfiguration.builder().networkMode(NetworkMode.PUBLIC).build())
|
||||
.roleArn(ROLE_ARN)
|
||||
.build()).agentRuntimeId();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (client != null) {
|
||||
try {
|
||||
client.deleteAgentRuntime(DeleteAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(runtimeId).build());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void defaultEndpointExists() {
|
||||
ListAgentRuntimeEndpointsResponse response = client.listAgentRuntimeEndpoints(
|
||||
ListAgentRuntimeEndpointsRequest.builder().agentRuntimeId(runtimeId).build());
|
||||
assertThat(response.runtimeEndpoints())
|
||||
.anyMatch(e -> "DEFAULT".equals(e.name()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void createEndpoint() {
|
||||
CreateAgentRuntimeEndpointResponse response = client.createAgentRuntimeEndpoint(
|
||||
CreateAgentRuntimeEndpointRequest.builder()
|
||||
.agentRuntimeId(runtimeId)
|
||||
.name("prod")
|
||||
.agentRuntimeVersion("1")
|
||||
.description("prod endpoint")
|
||||
.build());
|
||||
assertThat(response.endpointName()).isEqualTo("prod");
|
||||
assertThat(response.targetVersion()).isEqualTo("1");
|
||||
assertThat(response.statusAsString()).isEqualTo("READY");
|
||||
assertThat(response.agentRuntimeEndpointArn()).contains(":agentEndpoint/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getEndpoint() {
|
||||
GetAgentRuntimeEndpointResponse response = client.getAgentRuntimeEndpoint(
|
||||
GetAgentRuntimeEndpointRequest.builder()
|
||||
.agentRuntimeId(runtimeId).endpointName("prod").build());
|
||||
assertThat(response.name()).isEqualTo("prod");
|
||||
assertThat(response.targetVersion()).isEqualTo("1");
|
||||
assertThat(response.description()).isEqualTo("prod endpoint");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void listEndpoints() {
|
||||
ListAgentRuntimeEndpointsResponse response = client.listAgentRuntimeEndpoints(
|
||||
ListAgentRuntimeEndpointsRequest.builder().agentRuntimeId(runtimeId).build());
|
||||
assertThat(response.runtimeEndpoints()).extracting(AgentRuntimeEndpoint::name)
|
||||
.contains("DEFAULT", "prod");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void updateEndpoint() {
|
||||
client.updateAgentRuntimeEndpoint(UpdateAgentRuntimeEndpointRequest.builder()
|
||||
.agentRuntimeId(runtimeId).endpointName("prod").description("prod v2").build());
|
||||
|
||||
GetAgentRuntimeEndpointResponse response = client.getAgentRuntimeEndpoint(
|
||||
GetAgentRuntimeEndpointRequest.builder()
|
||||
.agentRuntimeId(runtimeId).endpointName("prod").build());
|
||||
assertThat(response.description()).isEqualTo("prod v2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void deleteEndpoint() {
|
||||
DeleteAgentRuntimeEndpointResponse response = client.deleteAgentRuntimeEndpoint(
|
||||
DeleteAgentRuntimeEndpointRequest.builder()
|
||||
.agentRuntimeId(runtimeId).endpointName("prod").build());
|
||||
assertThat(response.statusAsString()).isEqualTo("DELETING");
|
||||
|
||||
assertThatThrownBy(() -> client.getAgentRuntimeEndpoint(GetAgentRuntimeEndpointRequest.builder()
|
||||
.agentRuntimeId(runtimeId).endpointName("prod").build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.BedrockAgentCoreControlClient;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.model.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Bedrock AgentCore Gateway")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreGatewayTest {
|
||||
|
||||
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/gw";
|
||||
|
||||
private static BedrockAgentCoreControlClient client;
|
||||
private static String gatewayName;
|
||||
private static String gatewayId;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
client = TestFixtures.bedrockAgentCoreControlClient();
|
||||
gatewayName = "gw" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (client != null) {
|
||||
try {
|
||||
client.deleteGateway(DeleteGatewayRequest.builder().gatewayIdentifier(gatewayId).build());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createGateway() {
|
||||
CreateGatewayResponse response = client.createGateway(CreateGatewayRequest.builder()
|
||||
.name(gatewayName)
|
||||
.protocolType(GatewayProtocolType.MCP)
|
||||
.authorizerType(AuthorizerType.AWS_IAM)
|
||||
.roleArn(ROLE_ARN)
|
||||
.build());
|
||||
gatewayId = response.gatewayId();
|
||||
assertThat(gatewayId).isNotBlank();
|
||||
assertThat(response.gatewayArn()).contains(":gateway/");
|
||||
assertThat(response.gatewayUrl()).contains(gatewayId);
|
||||
assertThat(response.statusAsString()).isEqualTo("READY");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getGateway() {
|
||||
GetGatewayResponse response = client.getGateway(GetGatewayRequest.builder()
|
||||
.gatewayIdentifier(gatewayId).build());
|
||||
assertThat(response.name()).isEqualTo(gatewayName);
|
||||
assertThat(response.protocolTypeAsString()).isEqualTo("MCP");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listGateways() {
|
||||
ListGatewaysResponse response = client.listGateways(ListGatewaysRequest.builder().build());
|
||||
assertThat(response.items()).extracting(GatewaySummary::gatewayId).contains(gatewayId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void deleteGateway() {
|
||||
DeleteGatewayResponse response = client.deleteGateway(DeleteGatewayRequest.builder()
|
||||
.gatewayIdentifier(gatewayId).build());
|
||||
assertThat(response.statusAsString()).isEqualTo("DELETING");
|
||||
|
||||
assertThatThrownBy(() -> client.getGateway(GetGatewayRequest.builder()
|
||||
.gatewayIdentifier(gatewayId).build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.BedrockAgentCoreControlClient;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.model.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Bedrock AgentCore clientToken idempotency")
|
||||
class BedrockAgentCoreIdempotencyTest {
|
||||
|
||||
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/agent-runtime";
|
||||
|
||||
private static CreateAgentRuntimeRequest req(String name, String token) {
|
||||
return CreateAgentRuntimeRequest.builder()
|
||||
.agentRuntimeName(name)
|
||||
.agentRuntimeArtifact(AgentRuntimeArtifact.builder()
|
||||
.containerConfiguration(ContainerConfiguration.builder()
|
||||
.containerUri("public.ecr.aws/x/agent:latest").build())
|
||||
.build())
|
||||
.networkConfiguration(NetworkConfiguration.builder().networkMode(NetworkMode.PUBLIC).build())
|
||||
.roleArn(ROLE_ARN)
|
||||
.clientToken(token)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRuntimeWithSameClientTokenReturnsSameRuntime() {
|
||||
BedrockAgentCoreControlClient client = TestFixtures.bedrockAgentCoreControlClient();
|
||||
String name = "idem" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
// clientToken must be >= 33 chars of the allowed alphabet.
|
||||
String token = "idemtoken" + UUID.randomUUID().toString().replace("-", "");
|
||||
String id1 = null;
|
||||
try {
|
||||
id1 = client.createAgentRuntime(req(name, token)).agentRuntimeId();
|
||||
String id2 = client.createAgentRuntime(req(name, token)).agentRuntimeId();
|
||||
assertThat(id2).isEqualTo(id1);
|
||||
} finally {
|
||||
if (id1 != null) {
|
||||
try {
|
||||
client.deleteAgentRuntime(DeleteAgentRuntimeRequest.builder()
|
||||
.agentRuntimeId(id1).clientToken(token).build());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.core.ResponseBytes;
|
||||
import software.amazon.awssdk.core.SdkBytes;
|
||||
import software.amazon.awssdk.services.bedrockagentcore.BedrockAgentCoreClient;
|
||||
import software.amazon.awssdk.services.bedrockagentcore.model.InvokeAgentRuntimeRequest;
|
||||
import software.amazon.awssdk.services.bedrockagentcore.model.InvokeAgentRuntimeResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Bedrock AgentCore InvokeAgentRuntime (data plane)")
|
||||
class BedrockAgentCoreInvokeTest {
|
||||
|
||||
private static final String ARN =
|
||||
"arn:aws:bedrock-agentcore:us-east-1:000000000000:agent/abcdef12-3456-7890-abcd-ef1234567890:1";
|
||||
private static final String SESSION_ID = "session-0000000000000000000000000000abc";
|
||||
|
||||
@Test
|
||||
void invokeReturnsCannedBodyAndEchoesSession() {
|
||||
try (BedrockAgentCoreClient client = TestFixtures.bedrockAgentCoreClient()) {
|
||||
ResponseBytes<InvokeAgentRuntimeResponse> response = client.invokeAgentRuntimeAsBytes(
|
||||
InvokeAgentRuntimeRequest.builder()
|
||||
.agentRuntimeArn(ARN)
|
||||
.runtimeSessionId(SESSION_ID)
|
||||
.contentType("application/json")
|
||||
.payload(SdkBytes.fromUtf8String("{\"prompt\":\"anything\"}"))
|
||||
.build());
|
||||
|
||||
assertThat(response.asUtf8String()).contains("yes");
|
||||
assertThat(response.response().runtimeSessionId()).isEqualTo(SESSION_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.BedrockAgentCoreControlClient;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.model.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Bedrock AgentCore Memory")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreMemoryTest {
|
||||
|
||||
private static BedrockAgentCoreControlClient client;
|
||||
private static String memoryName;
|
||||
private static String memoryId;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
client = TestFixtures.bedrockAgentCoreControlClient();
|
||||
memoryName = "mem" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (client != null) {
|
||||
try {
|
||||
client.deleteMemory(DeleteMemoryRequest.builder().memoryId(memoryId).build());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createMemory() {
|
||||
CreateMemoryResponse response = client.createMemory(CreateMemoryRequest.builder()
|
||||
.name(memoryName)
|
||||
.eventExpiryDuration(30)
|
||||
.description("v1")
|
||||
.build());
|
||||
memoryId = response.memory().id();
|
||||
assertThat(memoryId).isNotBlank();
|
||||
assertThat(response.memory().name()).isEqualTo(memoryName);
|
||||
assertThat(response.memory().arn()).contains(":memory/");
|
||||
assertThat(response.memory().statusAsString()).isEqualTo("ACTIVE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getMemory() {
|
||||
GetMemoryResponse response = client.getMemory(GetMemoryRequest.builder().memoryId(memoryId).build());
|
||||
assertThat(response.memory().name()).isEqualTo(memoryName);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listMemories() {
|
||||
ListMemoriesResponse response = client.listMemories(ListMemoriesRequest.builder().build());
|
||||
assertThat(response.memories()).extracting(MemorySummary::id).contains(memoryId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void updateMemory() {
|
||||
UpdateMemoryResponse response = client.updateMemory(UpdateMemoryRequest.builder()
|
||||
.memoryId(memoryId).description("v2").build());
|
||||
assertThat(response.memory().id()).isEqualTo(memoryId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void deleteMemory() {
|
||||
DeleteMemoryResponse response = client.deleteMemory(DeleteMemoryRequest.builder()
|
||||
.memoryId(memoryId).build());
|
||||
assertThat(response.statusAsString()).isEqualTo("DELETING");
|
||||
|
||||
assertThatThrownBy(() -> client.getMemory(GetMemoryRequest.builder().memoryId(memoryId).build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.BedrockAgentCoreControlClient;
|
||||
import software.amazon.awssdk.services.bedrockagentcorecontrol.model.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@DisplayName("Bedrock AgentCore Tagging + Workload Identity")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class BedrockAgentCoreTagIdentityTest {
|
||||
|
||||
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/agent-runtime";
|
||||
|
||||
private static BedrockAgentCoreControlClient client;
|
||||
private static String runtimeArn;
|
||||
private static String identityName;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
client = TestFixtures.bedrockAgentCoreControlClient();
|
||||
String name = "tagAgent" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
runtimeArn = client.createAgentRuntime(CreateAgentRuntimeRequest.builder()
|
||||
.agentRuntimeName(name)
|
||||
.agentRuntimeArtifact(AgentRuntimeArtifact.builder()
|
||||
.containerConfiguration(ContainerConfiguration.builder()
|
||||
.containerUri("public.ecr.aws/x/agent:latest").build())
|
||||
.build())
|
||||
.networkConfiguration(NetworkConfiguration.builder().networkMode(NetworkMode.PUBLIC).build())
|
||||
.roleArn(ROLE_ARN)
|
||||
.build()).agentRuntimeArn();
|
||||
identityName = "wid" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (client != null) {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void tagRoundTrip() {
|
||||
client.tagResource(TagResourceRequest.builder()
|
||||
.resourceArn(runtimeArn).tags(Map.of("env", "prod", "team", "core")).build());
|
||||
|
||||
Map<String, String> tags = client.listTagsForResource(ListTagsForResourceRequest.builder()
|
||||
.resourceArn(runtimeArn).build()).tags();
|
||||
assertThat(tags).containsEntry("env", "prod").containsEntry("team", "core");
|
||||
|
||||
client.untagResource(UntagResourceRequest.builder()
|
||||
.resourceArn(runtimeArn).tagKeys(List.of("env")).build());
|
||||
|
||||
Map<String, String> after = client.listTagsForResource(ListTagsForResourceRequest.builder()
|
||||
.resourceArn(runtimeArn).build()).tags();
|
||||
assertThat(after).doesNotContainKey("env").containsEntry("team", "core");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void gatewayTagRoundTripViaSdk() {
|
||||
String gwName = "gwtag" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
|
||||
String gatewayArn = client.createGateway(CreateGatewayRequest.builder()
|
||||
.name(gwName)
|
||||
.protocolType(GatewayProtocolType.MCP)
|
||||
.authorizerType(AuthorizerType.AWS_IAM)
|
||||
.roleArn("arn:aws:iam::000000000000:role/gw")
|
||||
.build()).gatewayArn();
|
||||
try {
|
||||
client.tagResource(TagResourceRequest.builder()
|
||||
.resourceArn(gatewayArn).tags(Map.of("env", "prod")).build());
|
||||
assertThat(client.listTagsForResource(ListTagsForResourceRequest.builder()
|
||||
.resourceArn(gatewayArn).build()).tags()).containsEntry("env", "prod");
|
||||
client.untagResource(UntagResourceRequest.builder()
|
||||
.resourceArn(gatewayArn).tagKeys(List.of("env")).build());
|
||||
assertThat(client.listTagsForResource(ListTagsForResourceRequest.builder()
|
||||
.resourceArn(gatewayArn).build()).tags()).doesNotContainKey("env");
|
||||
} finally {
|
||||
// gatewayIdentifier is the id form; derive it from the ARN's last segment.
|
||||
String gatewayId = gatewayArn.substring(gatewayArn.lastIndexOf('/') + 1);
|
||||
try {
|
||||
client.deleteGateway(DeleteGatewayRequest.builder().gatewayIdentifier(gatewayId).build());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void workloadIdentityCrud() {
|
||||
CreateWorkloadIdentityResponse created = client.createWorkloadIdentity(
|
||||
CreateWorkloadIdentityRequest.builder().name(identityName).build());
|
||||
assertThat(created.name()).isEqualTo(identityName);
|
||||
assertThat(created.workloadIdentityArn()).contains(":bedrock-agentcore:");
|
||||
|
||||
GetWorkloadIdentityResponse got = client.getWorkloadIdentity(
|
||||
GetWorkloadIdentityRequest.builder().name(identityName).build());
|
||||
assertThat(got.name()).isEqualTo(identityName);
|
||||
|
||||
ListWorkloadIdentitiesResponse listed = client.listWorkloadIdentities(
|
||||
ListWorkloadIdentitiesRequest.builder().build());
|
||||
assertThat(listed.workloadIdentities()).extracting(WorkloadIdentityType::name)
|
||||
.contains(identityName);
|
||||
|
||||
client.deleteWorkloadIdentity(DeleteWorkloadIdentityRequest.builder().name(identityName).build());
|
||||
assertThatThrownBy(() -> client.getWorkloadIdentity(
|
||||
GetWorkloadIdentityRequest.builder().name(identityName).build()))
|
||||
.isInstanceOf(ResourceNotFoundException.class);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user