Skip to main content

AMAZON S3 WITH SWAMP

Swamp works with Amazon S3 in two ways. It manages S3 resources such as buckets, bucket policies and access points as behaviors. It can also keep its own data in an S3 bucket in place of the local datastore. Each of these is provided by an extension from the registry, and you can use either one without the other.

Get started

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

S3 resources as behaviors

The @swamp/aws/s3 extension provides one behavior type for each kind of S3 resource. A behavior of type @swamp/aws/s3/bucket describes a single bucket. Its versioning, encryption, public access block, lifecycle rules and other settings are global arguments in the behavior definition. The other types cover bucket policies, access points, Multi-Region Access Points and their policies, S3 Access Grants instances, locations and grants, and Storage Lens configurations and groups.

Every type has create, get, delete, sync and list methods, and all except @swamp/aws/s3/multi-region-access-point also have update. Each method writes the resource state it reads or changes into the repository's data. A later method, workflow step or report can read that state. The getting started tutorial defines a versioned private bucket and creates it. Enforce TLS-only access with an S3 bucket policy attaches a policy to a bucket that already exists.

The @jentz/aws-s3-bucket-audit report reads the bucket and bucket-policy state that these behaviors write. It checks the state against rules for versioning, encryption, public access, object ownership, TLS-only policies, lifecycle and logging.

Task-focused extensions

Some extensions are built around one task rather than one resource:

S3 as the Swamp datastore

The @swamp/s3-datastore extension stores a repository's data in an S3 bucket and keeps a local cache in sync with it. It uses S3 conditional writes as a distributed lock, so several machines and repositories can share one datastore. It also works with S3-compatible endpoints. @swamp/s3-datastore-bootstrap creates the bucket and a least-privilege IAM managed policy for it, as described in Provision an S3 bucket for the Swamp datastore.

Understanding Amazon S3 automation in Swamp covers how these pieces relate and how to choose between them. The extensions reference lists every type, global argument and method.

Amazon S3 documentation