bedrockruntime

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 28 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Bedrock Runtime

Parity grade: A · SDK aws-sdk-go-v2/service/bedrockruntime@v1.57.1 · last audited 2026-08-07 (8c56f4eb9)

Coverage

Metric Value
Operations audited 11 (10 ok, 1 partial)
Feature families 6 (6 ok)
Known gaps 6
Deferred items 0
Resource leaks clean
Known gaps
  • The generic pkgs/chaos FaultError shape ({code, statusCode} -> a plain {__type, message} JSON body) can inject any error code/status for InvokeModel/Converse/etc (verified: real ModelErrorException/ModelNotReadyException/ThrottlingException/ServiceUnavailableException are all restjson1 GetErrorInfo-resolvable from a body __type field, no X-Amzn-ErrorType header required), but cannot reproduce ModelErrorException's two extra members (OriginalStatusCode, ResourceName) since chaos.FaultError has no per-service extension point for them. Buildable (add optional extra-fields support to chaos.FaultError) but out of this pass's scope: it is shared pkgs/chaos infrastructure, not bedrockruntime-local, and touching it has blast radius across all 137 chaos-registered services. (bd: gopherstack-ayfw)
  • CountTokens' invokeModel-body token estimate uses raw decoded-byte length as a chars proxy (cannot know the tokenizer for arbitrary model-specific InvokeModel body formats); acceptable per parity rules (deterministic mock), documented as an approximation in code comments
  • Converse's guardrailConfig body field (GuardrailIdentifier/GuardrailVersion) is accepted opaquely (json.RawMessage, unparsed) but not validated for the identifier-requires-version precondition that InvokeModel's equivalent HEADER fields now enforce -- both fields are optional/unrequired on types.GuardrailConfiguration (no smithy 'required' trait, verified), so the real SDK client does not enforce this combination client-side either; low-value/out-of-budget this pass since Converse's mock inference doesn't depend on guardrail semantics to produce a valid response
  • StartAsyncInvoke does not validate the real, client-side-required 'modelInput' body member is present -- deliberately not added: the real aws-sdk-go-v2 client enforces this required struct field before ever constructing the HTTP request (addOpStartAsyncInvokeValidationMiddleware), so no real SDK-driven caller can produce a request that omits it; adding server-side validation for it would only add risk (touches ~8 existing test bodies) for a scenario no real client can trigger
  • InvokeGuardrailChecks' contentFilter (VIOLENCE/HATE/SEXUAL/MISCONDUCT/INSULTS) and promptAttack (JAILBREAK/PROMPT_INJECTION/PROMPT_LEAKAGE) checks always return an empty results list for a requested group instead of one severityScore entry per requested category: gopherstack has no real ML content/prompt-injection classifier, and a per-category score would be pure fabrication. Documented, not hidden -- see the op note above.
  • InvokeGuardrailChecks' sensitiveInformation check only genuinely detects EMAIL/PHONE/IP_ADDRESS/URL/AWS_ACCESS_KEY/MAC_ADDRESS/US_SOCIAL_SECURITY_NUMBER/CREDIT_DEBIT_CARD_NUMBER (literal, deterministic formats). Every other GuardrailChecksSensitiveInformationEntityType (NAME, ADDRESS, AGE, PASSWORD, DRIVER_ID, LICENSE_PLATE, AWS_SECRET_KEY, and the various bank/tax/passport/health-ID entity types) requires free-text NER or a jurisdiction-specific checksum this backend does not implement, so those types are honestly never matched rather than fabricated.

More

Documentation

Index

Constants

View Source
const (
	AsyncInvokeStatusInProgress = "InProgress"
	AsyncInvokeStatusCompleted  = "Completed"
	AsyncInvokeStatusFailed     = "Failed"
)

Async invoke status values.

View Source
const MaxInvocationHistory = maxInvocationHistory

MaxInvocationHistory is the exported value for testing.

Variables

View Source
var (
	// ErrValidation is returned when a request parameter fails validation.
	ErrValidation = errors.New("ValidationException")
	// ErrNotFound is returned when a requested resource does not exist.
	ErrNotFound = awserr.New("ResourceNotFoundException", awserr.ErrNotFound)
)

Sentinel errors for the bedrockruntime backend.

Functions

This section is empty.

Types

type AsyncInvoke

type AsyncInvoke struct {
	SubmitTime         time.Time
	LastModifiedTime   time.Time
	EndTime            *time.Time
	FailureMessage     *string
	ClientRequestToken *string
	Tags               map[string]string
	InvocationArn      string
	ModelArn           string
	OutputS3URI        string
	Status             string
}

AsyncInvoke records an asynchronous model invocation.

type Handler

type Handler struct {
	Backend *InMemoryBackend
	// contains filtered or unexported fields
}

Handler is the Echo HTTP handler for AWS Bedrock Runtime operations.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a new Bedrock Runtime handler backed by backend. backend must not be nil.

func (*Handler) ChaosOperations

func (h *Handler) ChaosOperations() []string

ChaosOperations returns all operations that can be fault-injected.

func (*Handler) ChaosRegions

func (h *Handler) ChaosRegions() []string

ChaosRegions returns all regions this handler instance handles.

func (*Handler) ChaosServiceName

func (h *Handler) ChaosServiceName() string

ChaosServiceName returns the lowercase AWS service name for fault rule matching. This must be "bedrock", not "bedrockruntime": real Bedrock Runtime signs every request with SigV4 service name "bedrock" (verified in aws-sdk-go-v2/service/bedrockruntime@v1.57.1's auth.go, serviceAuthOptions -- unconditional for every operation, no per-operation override), the same signing name the sibling services/bedrock (control plane) handler already declares. pkgs/chaos's Middleware extracts the fault-matching "service" string straight from the real Authorization header's SigV4 credential scope, so a ChaosServiceName that doesn't match the real signing name can never match real client traffic -- getTargets already merges entries that share one signing name across multiple handlers (its own doc comment cites S3/S3 Control as the existing precedent for this exact situation).

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(c *echo.Context) string

ExtractOperation returns the operation name from the request path.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(c *echo.Context) string

ExtractResource extracts the primary resource identifier from the request path. For metrics/logging purposes, returns stable low-cardinality values: model paths return the modelId, guardrail paths return the guardrailIdentifier, and /async-invoke item paths return "async-invoke" (stable, not the ARN).

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations returns the list of supported operations.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the Echo handler function for Bedrock Runtime requests.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority returns the routing priority.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Purge

func (h *Handler) Purge(ctx context.Context, cutoff time.Time)

Purge implements service.Purgeable by removing all Bedrock Runtime invocation records older than cutoff.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all backend state. Implements service.Resettable.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher returns a function that matches Bedrock Runtime requests. It matches paths for /model/, /guardrail/, and /async-invoke.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the background janitor.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend. Handler previously had no Snapshot/Restore of its own -- and neither did InMemoryBackend -- so cli.go's generic setupPersistence (which type-asserts the registered service.Registerable, i.e. the Handler, for a Snapshot/Restore pair) never picked BedrockRuntime up at all: dead wiring, with no persistence underneath it either. This delegation (matching the cleanrooms/codecommit pattern) is what wires BedrockRuntime into persistence for the first time.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker starts the background janitor for async invocations.

type InMemoryBackend

type InMemoryBackend struct {
	// contains filtered or unexported fields
}

InMemoryBackend stores Bedrock Runtime state in memory.

func NewInMemoryBackend

func NewInMemoryBackend(accountID, region string) *InMemoryBackend

NewInMemoryBackend creates a new InMemoryBackend with a background service context.

func NewInMemoryBackendWithContext

func NewInMemoryBackendWithContext(svcCtx context.Context, accountID, region string) *InMemoryBackend

NewInMemoryBackendWithContext creates a new InMemoryBackend whose background goroutines are bounded by svcCtx. If svcCtx is nil, context.Background is used.

func (*InMemoryBackend) AdvanceAsyncInvokesForTest

func (b *InMemoryBackend) AdvanceAsyncInvokesForTest(minAge time.Duration)

AdvanceAsyncInvokesForTest is a test helper that immediately advances all InProgress invocations whose age exceeds minAge. Pass 0 to advance all immediately.

func (*InMemoryBackend) GetAsyncInvoke

func (b *InMemoryBackend) GetAsyncInvoke(invocationArn string) (*AsyncInvoke, error)

GetAsyncInvoke returns the async invocation with the given ARN. Returns ErrNotFound if the invocation does not exist.

func (*InMemoryBackend) ListAsyncInvokes

func (b *InMemoryBackend) ListAsyncInvokes(filter ListAsyncInvokesFilter) []*AsyncInvoke

ListAsyncInvokes returns async invocations sorted by submit time (oldest first). An optional filter may restrict results by status.

func (*InMemoryBackend) ListInvocations

func (b *InMemoryBackend) ListInvocations() []*Invocation

ListInvocations returns all recorded invocations in insertion order (oldest first).

func (*InMemoryBackend) Purge

func (b *InMemoryBackend) Purge(ctx context.Context, cutoff time.Time)

Purge removes all model invocations recorded before the cutoff time.

func (*InMemoryBackend) RecordInvocation

func (b *InMemoryBackend) RecordInvocation(operation, modelID, input, output string) *Invocation

RecordInvocation stores a completed invocation in memory. When the ring is full, the oldest entry is evicted and a warning is logged via the background context.

func (*InMemoryBackend) Region

func (b *InMemoryBackend) Region() string

Region returns the AWS region this backend is configured for.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all backend state, returning the backend to its initial empty state.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore deserializes backend state from a snapshot. It implements persistence.Persistable.

func (*InMemoryBackend) RunJanitor

func (b *InMemoryBackend) RunJanitor(ctx context.Context, interval time.Duration)

RunJanitor periodically cleans up old async invocations and advances InProgress ones.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serializes the backend state to JSON. It implements persistence.Persistable.

func (*InMemoryBackend) StartAsyncInvoke

func (b *InMemoryBackend) StartAsyncInvoke(
	modelID, s3URI, clientToken string,
	tags map[string]string,
) (*AsyncInvoke, error)

StartAsyncInvoke creates a new asynchronous model invocation and returns it. If clientToken is non-empty and an invocation with that token already exists, the existing invocation is returned (idempotency). Returns an error if required parameters are missing.

type Invocation

type Invocation struct {
	CreatedAt time.Time
	ModelID   string
	Operation string
	Input     string
	Output    string
}

Invocation records a single model invocation.

type ListAsyncInvokesFilter

type ListAsyncInvokesFilter struct {
	// StatusEquals filters to invocations with the given status; empty means no filter.
	StatusEquals string
}

ListAsyncInvokesFilter holds optional filter criteria for listing async invocations.

type Provider

type Provider struct{}

Provider implements service.Provider for Bedrock Runtime.

func (*Provider) Init

Init initializes the Bedrock Runtime backend and handler.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL