streams

package
v6.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 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.

Documentation

Overview

Package streams reads DynamoDB Streams from the local profile.

DynamoDB Local implements the DynamoDB Streams API: a table created with a stream specification (or updated with UpdateTable) exposes DescribeTable.LatestStreamArn, and DescribeStream, GetShardIterator and GetRecords return the records of real writes. The harness therefore reads the stream AWS publishes rather than deriving a record from the stored item.

The record JSON this package emits is the Lambda stream-event shape: https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html

Two differences from a deployed event-source mapping are handled here and named in docs/examples/local-harness.md:

  • DynamoDB Streams records do not carry eventSourceARN; Lambda adds the stream ARN when it invokes the function. The reader fills it from the stream ARN DescribeTable/DescribeStream reports.
  • DynamoDB Local reports the stream ARN in the ddblocal region and does not run the TTL sweeper, so a delete it performs is not attributed to the TTL service. MarkTTLExpiry adds the documented Service identity to a REMOVE record the harness produced with a real DeleteItem. The identity shape is documented at https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-streams.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarkTTLExpiry

func MarkTTLExpiry(record *Record) bool

MarkTTLExpiry adds the documented DynamoDB TTL service identity to a REMOVE record the harness produced with a real delete. It reports whether it added the identity, so a caller can report that the TTL attribution is the one local substitution. DynamoDB Local does not run the TTL sweeper; the record's keys, images, event id, sequence number and stream ARN are the stream's.

func Read

func Read(
	ctx context.Context,
	client *dynamodbstreams.Client,
	streamARN string,
	match func(Record) bool,
	timeout time.Duration,
) ([]Record, Record, error)

Read polls the stream from TRIM_HORIZON until match accepts one of the records read so far, or the deadline expires. It returns every record it read, the matched record, and an error when no match arrived.

Types

type Event

type Event struct {
	Records []Record `json:"Records"`
}

Event is the Lambda stream-event envelope.

func EventFor

func EventFor(records ...Record) Event

EventFor wraps records in the Lambda event envelope.

type Identity

type Identity struct {
	Type        string `json:"type"`
	PrincipalID string `json:"principalId"`
}

Identity is the record's userIdentity block.

type Metadata

type Metadata struct {
	Table       string
	StreamARN   string
	StreamLabel string
}

Metadata identifies the stream a table exposes.

func Ensure

func Ensure(
	ctx context.Context,
	client *dynamodb.Client,
	table string,
	timeout time.Duration,
) (Metadata, error)

Ensure enables a NEW_AND_OLD_IMAGES stream on an existing table and returns the stream ARN. It is idempotent: a table that already has a stream is not updated again, so repeated harness rows reuse the same stream.

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"`
	EventSourceARN string    `json:"eventSourceARN"`
	UserIdentity   *Identity `json:"userIdentity,omitempty"`
	DynamoDB       Stream    `json:"dynamodb"`
}

Record is one DynamoDB stream record in the Lambda event shape.

type Stream

type Stream struct {
	Keys                        map[string]any `json:"Keys"`
	NewImage                    map[string]any `json:"NewImage,omitempty"`
	OldImage                    map[string]any `json:"OldImage,omitempty"`
	SequenceNumber              string         `json:"SequenceNumber"`
	StreamViewType              string         `json:"StreamViewType"`
	ApproximateCreationDateTime float64        `json:"ApproximateCreationDateTime,omitempty"`
	SizeBytes                   int64          `json:"SizeBytes"`
}

Stream is the record's dynamodb block. The fields are ordered so the pointer-bearing values come first; the JSON shape is unchanged.

Jump to

Keyboard shortcuts

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