DynamoDB
Read an item attribute from an Amazon DynamoDB table, built on aws-sdk-go-v2.
| Scheme | dynamodb:// |
| Module | github.com/xavidop/mamori/providers/dynamodb |
| Sensitive | no (opt-in with WithSensitive) |
| Watch | poll |
| Auth | default AWS credential chain (WithRegion) |
Install
go get github.com/xavidop/mamori/providers/dynamodb
import _ "github.com/xavidop/mamori/providers/dynamodb"
Using the ref
A dynamodb:// ref points at one item in a table, fetched by its primary key with a single GetItem.
dynamodb://<table>/<pk>[#attr][?pk_name=<name>&sk=<value>&sk_name=<name>]
| Part | Required | What it means |
|---|---|---|
<table> | yes | The DynamoDB table name. |
<pk> | yes | The partition-key value (a string). |
#attr | no | Return one top-level attribute instead of the whole item. Without it, the whole item comes back as JSON. |
?pk_name= | no | The partition-key attribute name. Defaults to pk. |
?sk= | no | The sort-key value, for a table with a composite primary key. |
?sk_name= | no | The sort-key attribute name. Defaults to sk. |
Examples
dynamodb://app-config/servicereads the item whosepkisserviceand returns the whole item as JSON.dynamodb://app-config/service#endpointreturns just theendpointattribute of that item.dynamodb://services/payments#url?pk_name=service_idlooks the item up by aservice_idpartition key instead of the defaultpk.dynamodb://events/e-1#payload?sk=2024&sk_name=yearreads an item with a composite key (partitionpk=e-1, sortyear=2024).
type Config struct {
Endpoint string `source:"dynamodb://app-config/service#endpoint"`
Whole string `source:"dynamodb://app-config/service"` // whole item as JSON
}
#attr selects a top-level DynamoDB attribute, not a nested JSON key: a scalar comes back stringified (S/N verbatim, BOOL as true/false, NULL as null), while maps, lists, and sets are JSON. Value.Version is the item’s version attribute when present (bump it to force a refresh), otherwise a content hash. Items are not marked sensitive by default; construct the provider with WithSensitive when a table holds secret material.
Watch
mamori polls (WithPollInterval + jitter). For push, DynamoDB Streams can drive an on-demand reload in your app.
Error classification
Failures are classified so mamori.ErrorKind can distinguish them:
| DynamoDB error code | mamori kind |
|---|---|
ResourceNotFoundException | not_found |
AccessDeniedException | permission_denied |
UnrecognizedClientException, ExpiredTokenException, InvalidSignatureException, MissingAuthenticationToken, IncompleteSignature | unauthenticated |
ProvisionedThroughputExceededException, ThrottlingException, RequestLimitExceeded, Throttling, TooManyRequestsException | rate_limited |
InternalServerError, ServiceUnavailable, InternalFailure | unavailable |
ValidationException | invalid |
| anything else | unknown |
Codes not listed above report unknown rather than being guessed at. ResourceNotFoundException is matched first as its typed *ddbtypes.ResourceNotFoundException shape before classification runs; the classifier also recognizes the raw code, so an untyped error carrying it still maps to not_found. The original SDK error stays reachable with errors.As.
Most codes come from DynamoDB’s own error reference or the AWS-wide Common Errors page (MissingAuthenticationToken, IncompleteSignature, Throttling, TooManyRequestsException, InternalFailure are AWS-wide codes, mapped the same way the AWS provider maps them for other services). ExpiredTokenException and InvalidSignatureException are real AWS signing and credential errors DynamoDB can return, but are not actually enumerated on either reference page.
Configuration
import ddbprov "github.com/xavidop/mamori/providers/dynamodb"
mamori.WithProvider(ddbprov.New(ddbprov.WithRegion("eu-west-1")))
Verified with an in-memory fake; live behavior is covered by //go:build integration tests.