tags = new ArrayList<>();
+ for (int i = 0; i < count; i++) {
+ tags.add(Tag.builder().key(prefix + i).value("v" + i).build());
+ }
+ return tags;
+ }
+
+ @Test
+ @Order(9)
+ void deleteGuardrailThenGetThrowsResourceNotFound() {
+ bedrock.deleteGuardrail(r -> r.guardrailIdentifier(guardrailId));
+
+ // The terraform provider's delete waiter matches this typed exception to treat
+ // the guardrail as gone.
+ String deletedId = guardrailId;
+ assertThatThrownBy(() -> bedrock.getGuardrail(r -> r.guardrailIdentifier(deletedId)))
+ .isInstanceOf(ResourceNotFoundException.class);
+
+ guardrailId = null;
+ }
+}
diff --git a/docs/services/bedrock.md b/docs/services/bedrock.md
new file mode 100644
index 0000000000..ef1cf5d96c
--- /dev/null
+++ b/docs/services/bedrock.md
@@ -0,0 +1,108 @@
+# Amazon Bedrock (control plane)
+
+**Protocol:** REST-JSON
+**Endpoint:** `http://localhost:4566/guardrails` (SigV4 service `bedrock`)
+
+This page covers the Bedrock control plane. Model invocation is a separate service
+that shares the same signing name: see [Bedrock Runtime](bedrock-runtime.md).
+
+## Supported Actions
+
+
+| Action | Description |
+| --- | --- |
+| `CreateGuardrail` | Create a guardrail; returns the `DRAFT` version, `READY` immediately |
+| `GetGuardrail` | Read a guardrail by id or ARN, at `DRAFT` or a numbered `guardrailVersion` |
+| `UpdateGuardrail` | Replace the `DRAFT` configuration |
+| `CreateGuardrailVersion` | Snapshot the `DRAFT` under the next numerical version |
+| `DeleteGuardrail` | Delete one numerical version, or the guardrail and all its versions |
+| `ListGuardrails` | List every guardrail's `DRAFT`, or every version of one guardrail |
+| `TagResource` | Tag a guardrail (`POST /tagResource`) |
+| `UntagResource` | Remove tags from a guardrail (`POST /untagResource`) |
+| `ListTagsForResource` | List a guardrail's tags (`POST /listTagsForResource`) |
+
+
+Guardrails are versioned. The working copy is `DRAFT`, and `GetGuardrail` without a
+`guardrailVersion` query parameter returns it. `CreateGuardrailVersion` copies the
+current `DRAFT` to `1`, `2` and so on. Those snapshots are immutable, because
+`UpdateGuardrail` only ever writes `DRAFT`.
+
+`GuardrailStatus` is `READY` from the first read, so `aws_bedrock_guardrail`'s status
+poll completes without a transition. Policy blocks are submitted as the `*Config`
+shapes (`topicPolicyConfig`, `contentPolicyConfig` and the rest) and read back under
+their unsuffixed names (`topicPolicy.topics`, `contentPolicy.filters`), matching the
+AWS model.
+
+`ListGuardrails` returns one `DRAFT` summary per guardrail. Passing
+`guardrailIdentifier` returns every version of that one guardrail instead. Both forms
+honour `maxResults` and `nextToken`.
+
+`DeleteGuardrail` takes a `GuardrailNumericalVersion`, so a version query parameter of
+`DRAFT` is rejected with `ValidationException`. Omit the parameter to delete the
+guardrail and all of its versions.
+
+Both an id (`abc123def456`) and a full ARN are accepted wherever the API takes a
+`guardrailIdentifier` or a `resourceARN`.
+
+`kmsKeyId` on `CreateGuardrail` and `UpdateGuardrail` is a `KmsKeyId`: a key id, a key
+ARN, an alias name or an alias ARN. `kmsKeyArn` on the read shapes is a `KmsKeyArn`,
+which is only ever the full key ARN, so every accepted form is resolved through KMS to
+that one shape. A key that does not exist, is disabled, or is pending deletion is
+rejected with `ValidationException`.
+
+The AWS model's length constraints are enforced: `name` is 1 to 50 characters matching
+`[0-9a-zA-Z-_]+`, `description` is 1 to 200, and `blockedInputMessaging` and
+`blockedOutputsMessaging` are 1 to 500 each. A value outside those bounds is rejected
+with `ValidationException`.
+
+The model's tag limits are enforced as well. A `TagList` holds at most 200 items on one
+request, and a longer array is rejected with `ValidationException`. A guardrail holds at
+most 50 tags, counted over the tags already on it together with the tags in the current
+request, so `CreateGuardrail` and `TagResource` both raise `TooManyTagsException` once
+the resulting total would pass 50. Replacing the value of a tag key the guardrail
+already carries does not add to that total.
+
+## Not implemented
+
+The rest of the Bedrock control plane is absent rather than stubbed, because
+emulating it faithfully would require behaviour Floci has no way to model:
+
+- `ListFoundationModels` and `GetFoundationModel`. The AWS service model carries no
+ enumeration of foundation model ids, so any catalogue would be invented data.
+- Custom model, model customization, model import and distillation jobs. These
+ depend on real training runs.
+- Model evaluation and evaluation jobs. These depend on real inference.
+- Provisioned throughput, inference profiles and prompt routers. These describe real
+ capacity reservations and routing.
+- Model invocation logging, batch inference and async invoke. These are data-plane
+ operations backed by real model execution.
+
+## Configuration
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_BEDROCK_ENABLED` | `true` | Enable or disable the service |
+
+## Examples
+
+```bash
+export AWS_ENDPOINT_URL=http://localhost:4566
+
+aws bedrock create-guardrail \
+ --name my-guardrail \
+ --blocked-input-messaging "Blocked." \
+ --blocked-outputs-messaging "Blocked." \
+ --content-policy-config '{"filtersConfig":[{"type":"HATE","inputStrength":"HIGH","outputStrength":"HIGH"}]}'
+
+aws bedrock get-guardrail --guardrail-identifier abc123def456
+
+aws bedrock create-guardrail-version --guardrail-identifier abc123def456
+
+aws bedrock list-guardrails
+
+aws bedrock tag-resource \
+ --resource-arn arn:aws:bedrock:us-east-1:000000000000:guardrail/abc123def456 \
+ --tags key=team,value=ai
+
+aws bedrock delete-guardrail --guardrail-identifier abc123def456
+```
diff --git a/docs/services/index.md b/docs/services/index.md
index 62ed2aaa09..1869eab0e6 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -89,6 +89,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [AppConfig](appconfig.md) | `/applications/...`, `/deploymentstrategies/...` | REST JSON | 16 |
| [AppConfigData](appconfig.md#data-plane) | `/configurationsessions`, `/configuration` | REST JSON | 2 |
| [AppSync](appsync.md) | `/v1/apis/...` | REST JSON | 33 |
+| [Amazon Bedrock](bedrock.md) | `/guardrails`, `/guardrails/{guardrailIdentifier}`, `/tagResource`, `/untagResource`, `/listTagsForResource` | REST JSON | 9 |
| [Bedrock Runtime](bedrock-runtime.md) | `/model/{modelId}/converse`, `/model/{modelId}/invoke` | REST JSON | 2 (stub; streaming returns 501) |
| [Bedrock AgentCore Control](bedrock-agentcore.md) | `/runtimes/*`, `/gateways/*`, `/memories/*`, `/identities/*`, `/browsers*`, `/browser-profiles*`, `/code-interpreters*`, `/resourcepolicy/*`, `/tags/{resourceArn}` | REST JSON | 61 (+ 3 tagging via shared `/tags/{arn}` route) |
| [Bedrock AgentCore](bedrock-agentcore.md#data-plane-invokeagentruntime) | `/runtimes/{agentRuntimeArn}/invocations` | REST JSON (binary payload) | 1 (canned-response stub) |
diff --git a/mkdocs.yml b/mkdocs.yml
index 336bd312ef..12e875b556 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -170,6 +170,7 @@ nav:
- EC2: services/ec2.md
- Lightsail: services/lightsail.md
- AppConfig: services/appconfig.md
+ - Bedrock: services/bedrock.md
- Bedrock Runtime: services/bedrock-runtime.md
- Bedrock AgentCore: services/bedrock-agentcore.md
- ELB v2: services/elb.md
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index 3b11cf1bcf..16e105057d 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -672,6 +672,7 @@ public interface EmulatorConfig {
AppConfigDataServiceConfig appconfigdata();
EcrServiceConfig ecr();
ResourceGroupsTaggingServiceConfig tagging();
+ BedrockServiceConfig bedrock();
BedrockRuntimeServiceConfig bedrockRuntime();
EksServiceConfig eks();
MwaaServiceConfig mwaa();
@@ -1751,6 +1752,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface BedrockServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface BedrockRuntimeServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 342cc74114..16d48caf80 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.services.backup.BackupController;
import io.github.hectorvent.floci.services.resourceexplorer2.ResourceExplorer2Controller;
import io.github.hectorvent.floci.services.appconfig.AppConfigDataController;
import io.github.hectorvent.floci.services.batch.BatchController;
+import io.github.hectorvent.floci.services.bedrock.BedrockController;
import io.github.hectorvent.floci.services.bedrockruntime.BedrockRuntimeController;
import io.github.hectorvent.floci.services.cognito.CognitoOAuthController;
import io.github.hectorvent.floci.services.cognito.CognitoWellKnownController;
@@ -317,6 +318,17 @@ public class ResolvedServiceCatalog {
config.storage().services().tagging().flushIntervalMs(), null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
Set.of("ResourceGroupsTaggingAPI_20170126."), Set.of("tagging"), Set.of(), Set.of()),
+ descriptor("bedrock", "bedrock", config.services().bedrock().enabled(), true,
+ "bedrock", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
+ protocols(ServiceProtocol.REST_JSON),
+ Set.of(),
+ // The control plane and bedrock-runtime both sign as "bedrock", and
+ // credential-scope registration is last-write-wins. bedrock-runtime
+ // already claims that scope; claiming it again here would move its
+ // enablement resolution onto this descriptor. Requests for these
+ // routes resolve through resourceClasses, which is checked first.
+ Set.of(), Set.of(),
+ Set.of(BedrockController.class)),
descriptor("bedrock-runtime", "bedrock-runtime",
config.services().bedrockRuntime().enabled(), true,
null, null, 5000L, null, ServiceProtocol.REST_JSON,
diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockController.java b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockController.java
new file mode 100644
index 0000000000..414033d375
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockController.java
@@ -0,0 +1,258 @@
+package io.github.hectorvent.floci.services.bedrock;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.Pagination;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.services.bedrock.model.Guardrail;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DELETE;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.PUT;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
+import java.time.Instant;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Amazon Bedrock control plane REST-JSON controller.
+ *
+ * Only the operations declared below are served. The data plane
+ * ({@code /model/{modelId}/...}) belongs to the separate bedrock-runtime service,
+ * which signs under the same {@code bedrock} name.
+ */
+@Path("/")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class BedrockController {
+
+ private final BedrockService bedrockService;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public BedrockController(BedrockService bedrockService, RegionResolver regionResolver,
+ ObjectMapper objectMapper) {
+ this.bedrockService = bedrockService;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ // Guardrails
+
+ @POST
+ @Path("/guardrails")
+ public Response createGuardrail(@Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ Guardrail guardrail = bedrockService.createGuardrail(readTree(body), region);
+
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("guardrailId", guardrail.getGuardrailId());
+ response.put("guardrailArn", guardrail.getGuardrailArn());
+ response.put("version", guardrail.getVersion());
+ response.put("createdAt", iso8601(guardrail.getCreatedAt()));
+ return Response.status(202).entity(response).build();
+ }
+
+ @GET
+ @Path("/guardrails/{guardrailIdentifier}")
+ public Response getGuardrail(@PathParam("guardrailIdentifier") String guardrailIdentifier,
+ @QueryParam("guardrailVersion") String guardrailVersion,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ Guardrail guardrail = bedrockService.getGuardrail(guardrailIdentifier, guardrailVersion, region);
+ return Response.ok(guardrailNode(guardrail)).build();
+ }
+
+ @PUT
+ @Path("/guardrails/{guardrailIdentifier}")
+ public Response updateGuardrail(@PathParam("guardrailIdentifier") String guardrailIdentifier,
+ @Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ Guardrail guardrail = bedrockService.updateGuardrail(guardrailIdentifier, readTree(body), region);
+
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("guardrailId", guardrail.getGuardrailId());
+ response.put("guardrailArn", guardrail.getGuardrailArn());
+ response.put("version", guardrail.getVersion());
+ response.put("updatedAt", iso8601(guardrail.getUpdatedAt()));
+ return Response.status(202).entity(response).build();
+ }
+
+ @POST
+ @Path("/guardrails/{guardrailIdentifier}")
+ public Response createGuardrailVersion(@PathParam("guardrailIdentifier") String guardrailIdentifier,
+ @Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ JsonNode request = readTree(body);
+ Guardrail version = bedrockService.createGuardrailVersion(guardrailIdentifier,
+ textOrNull(request, "description"), region);
+
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("guardrailId", version.getGuardrailId());
+ response.put("version", version.getVersion());
+ return Response.status(202).entity(response).build();
+ }
+
+ @DELETE
+ @Path("/guardrails/{guardrailIdentifier}")
+ public Response deleteGuardrail(@PathParam("guardrailIdentifier") String guardrailIdentifier,
+ @QueryParam("guardrailVersion") String guardrailVersion,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ bedrockService.deleteGuardrail(guardrailIdentifier, guardrailVersion, region);
+ return Response.status(202).build();
+ }
+
+ @GET
+ @Path("/guardrails")
+ public Response listGuardrails(@QueryParam("guardrailIdentifier") String guardrailIdentifier,
+ @QueryParam("maxResults") String maxResults,
+ @QueryParam("nextToken") String nextToken,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ PaginatedResult page = bedrockService.listGuardrails(guardrailIdentifier,
+ Pagination.parseMaxResults(maxResults, "ValidationException"), nextToken, region);
+
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode summaries = response.putArray("guardrails");
+ for (Guardrail guardrail : page.items()) {
+ summaries.add(guardrailSummaryNode(guardrail));
+ }
+ if (page.nextToken() != null) {
+ response.put("nextToken", page.nextToken());
+ }
+ return Response.ok(response).build();
+ }
+
+ // Tags
+
+ @POST
+ @Path("/tagResource")
+ public Response tagResource(@Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ JsonNode request = readTree(body);
+ bedrockService.tagResource(textOrNull(request, "resourceARN"),
+ BedrockService.parseTagList(request.get("tags")), region);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ @POST
+ @Path("/untagResource")
+ public Response untagResource(@Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ JsonNode request = readTree(body);
+ List tagKeys = new ArrayList<>();
+ JsonNode keys = request.get("tagKeys");
+ if (keys != null && keys.isArray()) {
+ keys.forEach(key -> tagKeys.add(key.asText()));
+ }
+ bedrockService.untagResource(textOrNull(request, "resourceARN"), tagKeys, region);
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ @POST
+ @Path("/listTagsForResource")
+ public Response listTagsForResource(@Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ JsonNode request = readTree(body);
+ Map tags = bedrockService.listTags(textOrNull(request, "resourceARN"), region);
+
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode array = response.putArray("tags");
+ tags.forEach((key, value) -> {
+ ObjectNode tag = array.addObject();
+ tag.put("key", key);
+ tag.put("value", value);
+ });
+ return Response.ok(response).build();
+ }
+
+ // Helpers
+
+ private ObjectNode guardrailNode(Guardrail guardrail) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("name", guardrail.getName());
+ if (guardrail.getDescription() != null) {
+ node.put("description", guardrail.getDescription());
+ }
+ node.put("guardrailId", guardrail.getGuardrailId());
+ node.put("guardrailArn", guardrail.getGuardrailArn());
+ node.put("version", guardrail.getVersion());
+ node.put("status", BedrockService.READY);
+ setIfPresent(node, "topicPolicy", guardrail.getTopicPolicy());
+ setIfPresent(node, "contentPolicy", guardrail.getContentPolicy());
+ setIfPresent(node, "wordPolicy", guardrail.getWordPolicy());
+ setIfPresent(node, "sensitiveInformationPolicy", guardrail.getSensitiveInformationPolicy());
+ setIfPresent(node, "contextualGroundingPolicy", guardrail.getContextualGroundingPolicy());
+ setIfPresent(node, "automatedReasoningPolicy", guardrail.getAutomatedReasoningPolicy());
+ setIfPresent(node, "crossRegionDetails", guardrail.getCrossRegionDetails());
+ node.put("createdAt", iso8601(guardrail.getCreatedAt()));
+ node.put("updatedAt", iso8601(guardrail.getUpdatedAt()));
+ node.put("blockedInputMessaging", guardrail.getBlockedInputMessaging());
+ node.put("blockedOutputsMessaging", guardrail.getBlockedOutputsMessaging());
+ if (guardrail.getKmsKeyArn() != null) {
+ node.put("kmsKeyArn", guardrail.getKmsKeyArn());
+ }
+ return node;
+ }
+
+ private ObjectNode guardrailSummaryNode(Guardrail guardrail) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("id", guardrail.getGuardrailId());
+ node.put("arn", guardrail.getGuardrailArn());
+ node.put("status", BedrockService.READY);
+ node.put("name", guardrail.getName());
+ if (guardrail.getDescription() != null) {
+ node.put("description", guardrail.getDescription());
+ }
+ node.put("version", guardrail.getVersion());
+ node.put("createdAt", iso8601(guardrail.getCreatedAt()));
+ node.put("updatedAt", iso8601(guardrail.getUpdatedAt()));
+ setIfPresent(node, "crossRegionDetails", guardrail.getCrossRegionDetails());
+ return node;
+ }
+
+ private void setIfPresent(ObjectNode node, String field, JsonNode value) {
+ if (value != null && !value.isNull()) {
+ node.set(field, value);
+ }
+ }
+
+ private String iso8601(Instant instant) {
+ return DateTimeFormatter.ISO_INSTANT.format(instant);
+ }
+
+ private JsonNode readTree(String body) {
+ try {
+ return objectMapper.readTree(body == null || body.isBlank() ? "{}" : body);
+ } catch (Exception e) {
+ throw new WebApplicationException(JsonErrorResponseUtils.createSerializationErrorResponse());
+ }
+ }
+
+ private String textOrNull(JsonNode node, String field) {
+ JsonNode value = node.get(field);
+ if (value == null || value.isNull()) {
+ return null;
+ }
+ return value.asText();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java
new file mode 100644
index 0000000000..024ebbddc4
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/bedrock/BedrockService.java
@@ -0,0 +1,529 @@
+package io.github.hectorvent.floci.services.bedrock;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.Pagination;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.bedrock.model.Guardrail;
+import io.github.hectorvent.floci.services.kms.KmsService;
+import io.github.hectorvent.floci.services.kms.model.KmsKey;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+/**
+ * Amazon Bedrock control plane (signing name {@code bedrock}). Guardrails are
+ * versioned: the working copy is {@code DRAFT} and {@code CreateGuardrailVersion}
+ * snapshots it under the next numerical version. Every guardrail is READY as soon
+ * as it is created, so {@code aws_bedrock_guardrail}'s status poll completes on its
+ * first read.
+ *
+ * Model invocation is a separate service, {@code bedrock-runtime}, which shares
+ * this signing name but serves the {@code /model/...} routes.
+ */
+@ApplicationScoped
+public class BedrockService {
+
+ public static final String DRAFT_VERSION = "DRAFT";
+ public static final String READY = "READY";
+
+ private static final Logger LOG = Logger.getLogger(BedrockService.class);
+
+ /** {@code GuardrailName} from the AWS model. */
+ private static final Pattern NAME_PATTERN = Pattern.compile("[0-9a-zA-Z\\-_]{1,50}");
+
+ /** {@code GuardrailNumericalVersion} from the AWS model. */
+ private static final Pattern NUMERICAL_VERSION_PATTERN = Pattern.compile("[1-9][0-9]{0,7}");
+
+ /** {@code GuardrailDescription} from the AWS model: min 1, max 200. */
+ private static final int DESCRIPTION_MAX = 200;
+
+ /** {@code GuardrailBlockedMessaging} from the AWS model: min 1, max 500. */
+ private static final int BLOCKED_MESSAGING_MAX = 500;
+
+ /** {@code MaxResults} on {@code ListGuardrails} is capped at 1000 by the AWS model. */
+ private static final int MAX_PAGE = 1000;
+
+ /** {@code TagList} from the AWS model: at most 200 items on one request. */
+ private static final int TAG_LIST_MAX = 200;
+
+ /**
+ * {@code TooManyTagsException} documents a limit of 50 tags per resource, counted over the
+ * tags already on the resource together with the tags carried by the current request.
+ */
+ private static final int TAGS_PER_RESOURCE_MAX = 50;
+
+ /**
+ * Policy blocks arrive as {@code *Config} shapes on create and update, and are read back
+ * as their unsuffixed counterparts. The member structures are identical in the AWS
+ * model, only these container keys are renamed.
+ */
+ private static final Map POLICY_MEMBER_RENAMES = Map.of(
+ "topicsConfig", "topics",
+ "filtersConfig", "filters",
+ "tierConfig", "tier",
+ "wordsConfig", "words",
+ "managedWordListsConfig", "managedWordLists",
+ "piiEntitiesConfig", "piiEntities",
+ "regexesConfig", "regexes");
+
+ private final StorageBackend guardrails;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+ private final KmsService kmsService;
+
+ @Inject
+ public BedrockService(StorageFactory storageFactory, RegionResolver regionResolver,
+ ObjectMapper objectMapper, KmsService kmsService) {
+ this(storageFactory.create("bedrock", "bedrock-guardrails.json",
+ new TypeReference