DynamoDB

Read an item attribute from an Amazon DynamoDB table, built on aws-sdk-go-v2.

Schemedynamodb://
Modulegithub.com/xavidop/mamori/providers/dynamodb
Sensitiveno (opt-in with WithSensitive)
Watchpoll
Authdefault 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>]
PartRequiredWhat it means
<table>yesThe DynamoDB table name.
<pk>yesThe partition-key value (a string).
#attrnoReturn one top-level attribute instead of the whole item. Without it, the whole item comes back as JSON.
?pk_name=noThe partition-key attribute name. Defaults to pk.
?sk=noThe sort-key value, for a table with a composite primary key.
?sk_name=noThe sort-key attribute name. Defaults to sk.

Examples

  • dynamodb://app-config/service reads the item whose pk is service and returns the whole item as JSON.
  • dynamodb://app-config/service#endpoint returns just the endpoint attribute of that item.
  • dynamodb://services/payments#url?pk_name=service_id looks the item up by a service_id partition key instead of the default pk.
  • dynamodb://events/e-1#payload?sk=2024&sk_name=year reads an item with a composite key (partition pk = e-1, sort year = 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 codemamori kind
ResourceNotFoundExceptionnot_found
AccessDeniedExceptionpermission_denied
UnrecognizedClientException, ExpiredTokenException, InvalidSignatureException, MissingAuthenticationToken, IncompleteSignatureunauthenticated
ProvisionedThroughputExceededException, ThrottlingException, RequestLimitExceeded, Throttling, TooManyRequestsExceptionrate_limited
InternalServerError, ServiceUnavailable, InternalFailureunavailable
ValidationExceptioninvalid
anything elseunknown

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.