dynamodb

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package dynamodb persists idempotency records in AWS DynamoDB.

New constructs a Store from an application-owned AWS SDK v2 Client and Options describing the table and persistence attributes. Supply the store to the core Idempotency manager, which owns keys, expiry and business execution.

Storage contract

Conditional writes acquire claims atomically; reads return consistent record snapshots. Completed responses are stored as JSON data. The application provisions the table, TTL policy and IAM permissions.

Store methods preserve cancellation and service error chains. The documented record format and expiry conventions support the scoped compatibility contract; review the guide before sharing a table with other implementations.

For usage and compatibility details, see the user guide.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	PutItem(context.Context, *sdk.PutItemInput, ...func(*sdk.Options)) (*sdk.PutItemOutput, error)
	GetItem(context.Context, *sdk.GetItemInput, ...func(*sdk.Options)) (*sdk.GetItemOutput, error)
	UpdateItem(context.Context, *sdk.UpdateItemInput, ...func(*sdk.Options)) (*sdk.UpdateItemOutput, error)
	DeleteItem(context.Context, *sdk.DeleteItemInput, ...func(*sdk.Options)) (*sdk.DeleteItemOutput, error)
}

type Options

type Options struct {
	TableName                                                   string
	KeyAttribute, SortKeyAttribute, StaticPartitionKey          string
	StatusAttribute, ExpiryAttribute, InProgressExpiryAttribute string
	DataAttribute, ValidationAttribute                          string
}

Options maps the reference attribute names. A sort key enables a static partition key, defaulting to idempotency#<AWS_LAMBDA_FUNCTION_NAME>.

type Store

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

func New

func New(client Client, options Options) (*Store, error)
Example

Actual persistence operations require a provisioned table and AWS permissions.

package main

import (
	"github.com/aws/aws-sdk-go-v2/aws"
	sdk "github.com/aws/aws-sdk-go-v2/service/dynamodb"
	"github.com/rambow-cloud/powertools-lambda-go/idempotency"
	"github.com/rambow-cloud/powertools-lambda-go/idempotency/dynamodb"
)

func main() {
	// Supply the application's credentials provider before persistence operations.
	cfg := aws.Config{Region: "ap-east-1"}
	store, err := dynamodb.New(sdk.NewFromConfig(cfg), dynamodb.Options{
		TableName: "example-idempotency",
	})
	if err != nil {
		panic(err)
	}
	manager, err := idempotency.New(store, idempotency.Options{
		KeyPrefix: "orders", EventKeyJMESPath: "orderId",
	})
	if err != nil {
		panic(err)
	}
	_ = manager // Reuse this manager when wrapping business operations.
}

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (idempotency.Record, error)

func (*Store) Put

func (s *Store) Put(ctx context.Context, record idempotency.Record, now time.Time) error

func (*Store) Update

func (s *Store) Update(ctx context.Context, record idempotency.Record) error

Jump to

Keyboard shortcuts

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