Help us shape the future of Go! Take the 2026 Go Developer Survey

dynamodb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package dynamodb emulates Amazon DynamoDB and DynamoDB Streams over JSON 1.0: tables with global and local secondary indexes, every expression type, conditional writes, batches, transactions, TTL expiry and change streams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backup

type Backup struct {
	Arn     string    `json:"arn"`
	Name    string    `json:"name"`
	Account string    `json:"account"`
	Region  string    `json:"region"`
	Created time.Time `json:"created"`
	Deleted bool      `json:"deleted,omitempty"`
	Table   *Table    `json:"table"`
}

Backup is an on-demand backup: the table as it was, items included.

type Item

type Item map[string]*Value

Item is an item or a key: attribute name → value. Stored items are never changed in place (updates work on copies), so responses may share them.

type Record

type Record struct {
	EventID      string       `json:"eventID"`
	EventName    string       `json:"eventName"`
	EventVersion string       `json:"eventVersion"`
	EventSource  string       `json:"eventSource"`
	AwsRegion    string       `json:"awsRegion"`
	Dynamodb     streamRecord `json:"dynamodb"`
	UserIdentity *identity    `json:"userIdentity,omitempty"`
}

Record is a stream record in the DynamoDB Streams (and Lambda event) shape.

type Service

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

Service is the DynamoDB and DynamoDB Streams emulator.

func New

func New(hub *core.Hub) *Service

New creates the service and starts its TTL sweeper.

func (*Service) Apply

func (s *Service) Apply(key string, v []byte) error

Apply replays a journal record: t/ tables (without items), i/ items, s/ streams, r/ stream records, x/ transaction tokens and b/ backups.

func (*Service) Close

func (s *Service) Close() error

Close stops the TTL sweeper.

func (*Service) DeleteItemJSON

func (s *Service) DeleteItemJSON(account, region, table string, key map[string]any) error

DeleteItemJSON deletes the item with a key given in DynamoDB JSON, for the console.

func (*Service) ExpireTTL

func (s *Service) ExpireTTL(now time.Time)

ExpireTTL deletes the items whose TTL attribute (epoch seconds) is at or before now, as the background sweeper does every few seconds. Like DynamoDB, it ignores TTLs more than five years in the past.

func (*Service) Info

func (s *Service) Info() core.Info

func (*Service) Inspect

func (s *Service) Inspect(table, id string) any

Inspect returns a table's description and up to 20 of its items. ponytail: tables are found by name alone; the first account/region wins.

func (*Service) Items

func (s *Service) Items(account, region, table string, limit int) ([]map[string]any, error)

Items returns up to limit items (all when limit <= 0) in DynamoDB JSON, e.g. {"id":{"S":"1"}}, for the console.

func (*Service) Load

func (s *Service) Load(b []byte) error

func (*Service) PutItemJSON

func (s *Service) PutItemJSON(account, region, table string, item map[string]any) error

PutItemJSON stores an item given in DynamoDB JSON, for the console.

func (*Service) Reset

func (s *Service) Reset()

func (*Service) Resources

func (s *Service) Resources() []core.Table

Resources lists tables for the console.

func (*Service) Save

func (s *Service) Save() ([]byte, error)

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is core.RPC's JSON path plus apiError members and the X-Amz-Crc32 header, which DynamoDB SDKs verify.

func (*Service) SetJournal

func (s *Service) SetJournal(j *core.Journal)

SetJournal logs every change of tables, items and streams (wal mode).

func (*Service) TaggedResources

func (s *Service) TaggedResources(account, region string) map[string]map[string]string

TaggedResources lists tables (ARN → tags) for the tagging API and Resource Explorer.

type Stream

type Stream struct {
	Arn     string    `json:"arn"`
	Label   string    `json:"label"`
	Table   string    `json:"table"`
	Account string    `json:"account"`
	Region  string    `json:"region"`
	View    string    `json:"view"`
	Enabled bool      `json:"enabled"`
	Created time.Time `json:"created"`
	Keys    []keyElem `json:"keys"`
	Shard   string    `json:"shard"`
	Seq     int64     `json:"seq"` // last sequence number handed out
	Records []*Record `json:"records"`
}

Stream is a table's change stream: one shard with the latest records.

type Table

type Table struct {
	Name       string            `json:"name"`
	Account    string            `json:"account"`
	Region     string            `json:"region"`
	ID         string            `json:"id"`
	Created    time.Time         `json:"created"`
	Attrs      []attrDef         `json:"attrs"`
	Keys       []keyElem         `json:"keys"`
	GSIs       []*index          `json:"gsis,omitempty"`
	LSIs       []*index          `json:"lsis,omitempty"`
	Billing    string            `json:"billing"`
	Throughput *throughput       `json:"throughput,omitempty"`
	StreamArn  string            `json:"streamArn,omitempty"` // latest stream, possibly disabled
	SSE        *sseSpec          `json:"sse,omitempty"`
	Class      string            `json:"class"`
	Protected  bool              `json:"protected,omitempty"`
	TTL        string            `json:"ttl,omitempty"` // TTL attribute while enabled
	PITR       bool              `json:"pitr,omitempty"`
	Replicas   []string          `json:"replicas,omitempty"` // other regions of a global table
	Restore    *restoreSummary   `json:"restore,omitempty"`
	Tags       map[string]string `json:"tags,omitempty"`
	Items      map[string]Item   `json:"items"` // keyOf(primary key) → item
}

Table is one table and its items.

type Value

type Value struct {
	S    *string
	N    *string
	B    []byte
	BOOL *bool
	NULL bool
	M    map[string]*Value
	L    []*Value
	SS   []string
	NS   []string
	BS   [][]byte
}

Value is one attribute value in DynamoDB JSON. Exactly one field is set; nil means unset, so empty maps, lists and binaries survive a round trip.

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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