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 ¶
- type Client
- type Options
- type Store
- func (s *Store) Delete(ctx context.Context, key string) error
- func (s *Store) Get(ctx context.Context, key string) (idempotency.Record, error)
- func (s *Store) Put(ctx context.Context, record idempotency.Record, now time.Time) error
- func (s *Store) Update(ctx context.Context, record idempotency.Record) error
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 ¶
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.
}
Output: