Skip to main content

AMAZON DYNAMODB WITH SWAMP

Amazon DynamoDB has two roles in Swamp. It can be infrastructure you manage, with tables defined as behaviors and changed by running their methods. It can also be the datastore where a Swamp repository keeps its own runtime data, locks and sync state. Each role uses different extensions.

Get started

curl -fsSL https://swamp-club.com/install.sh | sh
swamp repo init
swamp extension pull @swamp/aws/dynamodb
swamp extension pull @webframp/dynamodb-datastore
swamp extension pull @webframp/dynamodb-datastore-bootstrap

Managing tables

The @swamp/aws/dynamodb extension provides one behavior type, @swamp/aws/dynamodb/global-table. A behavior of this type describes a DynamoDB global table in its global arguments: TableName, KeySchema, AttributeDefinitions, BillingMode, Replicas, secondary indexes, streams, time to live, warm throughput and multi-region consistency. Replicas is required, so a table in a single region is described as a global table with one replica.

The type has six methods. create, update and delete change the table in AWS. get, list and sync read tables from AWS without changing them. Every method writes the table's resource state to Swamp data, so the recorded state can be queried, versioned and used by workflows like any other data.

By default the behavior uses credentials and the region from the AWS environment. The accessKeyId, secretAccessKey and sessionToken global arguments override the environment and are set with vault.get() expressions, so secrets stay in a vault rather than in the definition. The region global argument defaults to us-east-1.

The getting started tutorial defines a single-region table and builds it in AWS. To replicate a table between regions, see Create a multi-region DynamoDB global table. To record tables that already exist without changing them, see List and inspect existing DynamoDB global tables.

Storing Swamp data in DynamoDB

The @webframp/dynamodb-datastore extension is a datastore provider. It keeps a repository's runtime data in one DynamoDB table, takes distributed locks with conditional writes, splits items larger than DynamoDB's 400KB item limit into chunks, and emits OpenTelemetry spans for its operations.

The @webframp/dynamodb-datastore-bootstrap extension prepares AWS for it. Its bootstrap workflow creates the table and a least-privilege IAM managed policy, then switches the current repository to the DynamoDB datastore. Store Swamp runtime data in a DynamoDB datastore walks through the bootstrap.

The extensions reference lists every global argument, method and configuration key. Understanding DynamoDB automation in Swamp covers how the two roles fit together and the decisions involved in modelling tables.

Amazon DynamoDB documentation