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-bootstrapManaging 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
Getting started with Amazon DynamoDB in Swamp
Pull the DynamoDB extension, create a global table behavior with a key schema and single replica, validate it offline, and run its create method against AWS.
Tutorials →Create a multi-region DynamoDB global table
Define a DynamoDB global table behavior with replicas in two AWS regions and a stream specification, validate the definition, then create it and sync its state.
How-to Guides →List and inspect existing DynamoDB global tables
Use the list and get methods of a DynamoDB global table behavior to read existing tables from AWS into Swamp data, then query the stored resource state.
How-to Guides →Store Swamp runtime data in a DynamoDB datastore
Run the bootstrap workflow that provisions a DynamoDB table and a least-privilege IAM policy, then switches the current repository to the DynamoDB datastore.
How-to Guides →Amazon DynamoDB extensions
Every Swamp extension for Amazon DynamoDB: behavior types, global arguments, methods, vault configuration and the data each one writes, read from the registry.
Reference →Understanding DynamoDB automation in Swamp
How DynamoDB global tables map onto Swamp behaviors, methods and resource data, and when to use DynamoDB as the datastore that holds Swamp's own state.
Explanation →