bedrockruntime

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 32 Imported by: 0

README

Bedrock Runtime

Parity grade: A · SDK aws-sdk-go-v2/service/bedrockruntime@v1.57.1 · last audited 2026-09-18 (d4dc4a723)

Coverage

Metric Value
PARITY entries audited 11 (10 ok, 1 partial)
Feature families 6 (6 ok)
Known gaps 8
Deferred items 0
Resource leaks clean
Known gaps
  • chaos.FaultError cannot carry ModelErrorException's OriginalStatusCode/ResourceName: shared pkgs/chaos infrastructure with no per-service extension point (bd: gopherstack-ayfw).
  • No real inference or classifier: CountTokens estimates from byte length, Converse/InvokeModel return a canned reply, InvokeGuardrailChecks contentFilter/promptAttack return empty results and sensitiveInformation matches only the literal-format entity types (EMAIL/PHONE/IP_ADDRESS/URL/AWS_ACCESS_KEY/MAC_ADDRESS/US_SSN/CREDIT_DEBIT_CARD_NUMBER), never NER-based ones.
  • AsyncInvokeStatusFailed/FailureMessage are unreachable: the janitor only moves InProgress -> Completed and no AWS-documented trigger exists to key a Failed transition off.
  • Converse guardrailConfig is opaque and not checked for identifier-requires-version: no AWS doc states that rule for the Converse body (InvokeModel's header rule is documented).
  • No model behind Converse/ConverseStream/InvokeModel: InvokeModel.Body is never interpreted; AdditionalModelRequestFields, AdditionalModelResponseFieldPaths (so no AdditionalModelResponseFields), OutputConfig (structured output), PromptVariables (prompt-management modelId) and RequestMetadata (invocation-log filtering) are accepted but cannot change a canned reply.
  • InvokeModel/InvokeModelWithResponseStream Trace is enum-validated but no guardrail trace is ever produced, and RequestMetadata is not validated (no documented bounds in the pinned SDK).
  • ApplyGuardrail.OutputScope is enum-validated; FULL has no extra output to add because only word-policy assessments exist (the SDK says FULL does not apply to word filters).
  • Converse/InvokeModel serviceTier and performanceConfig latency are echoed from the request, not negotiated: no tiers or latency-optimized hosting exist to fall back from.

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")
	// ErrConflict is returned when a client token is replayed with different parameters.
	ErrConflict = errors.New("ConflictException")
	// 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
	Fingerprint        string `json:",omitempty"`
}

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) BackendFor

func (h *Handler) BackendFor(region string) *InMemoryBackend

BackendFor returns the backend serving region: the home backend, or the sibling built on first use.

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) EnableRegions

func (h *Handler) EnableRegions()

EnableRegions makes h serve every other region through lazily built per-region siblings.

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) RegionBackends

func (h *Handler) RegionBackends() []*InMemoryBackend

RegionBackends returns the home backend followed by every sibling built so far.

func (*Handler) RegionHandler

func (h *Handler) RegionHandler(region string) *Handler

RegionHandler returns the handler serving region: h itself for the home region, else its sibling.

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; sibling janitors stop as the old siblings are dropped.

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 janitors of h and every sibling.

func (*Handler) Snapshot

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

Snapshot implements persistence.Persistable; other regions ride in an additive "regions" key.

func (*Handler) StartWorker

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

StartWorker starts the async-invocation janitor of h and every sibling.

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.

func (*InMemoryBackend) StartAsyncInvokeFingerprinted

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

StartAsyncInvokeFingerprinted is StartAsyncInvoke plus a request fingerprint: replaying a token with a different non-empty fingerprint is a ConflictException.

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 {
	// SubmitTimeAfter, if set, excludes invocations submitted at or before this time.
	SubmitTimeAfter *time.Time
	// SubmitTimeBefore, if set, excludes invocations submitted at or after this time.
	SubmitTimeBefore *time.Time
	// StatusEquals filters to invocations with the given status; empty means no filter.
	StatusEquals string
	// SortOrder reverses SubmitTime ordering when set to
	// asyncInvokeSortOrderDescending; any other value (including empty) sorts ascending.
	SortOrder 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