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-bootstrapS3 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:
- @mgreten/aws/s3-site-deploy uploads new and changed site files to a bucket, using MD5 hashes to find the changes, and removes stale objects. See Deploy a static site to an S3 bucket.
- @mgreten/s3-object-read verifies read access, then lists or downloads objects from S3-compatible storage within a prefix and with size limits.
- @mgreten/s3-backup-retention creates a backup retention plan that deletes nothing, then applies only a plan that has been confirmed exactly.
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
Getting started with Amazon S3 in Swamp
Pull the @swamp/aws/s3 extension, define a versioned private bucket as a Swamp behavior, validate it offline, and run its create method against an AWS account.
Tutorials →Deploy a static site to an S3 bucket
Use the @mgreten/aws/s3-site-deploy behavior to upload changed site files to an S3 bucket by MD5 comparison and remove stale objects missing from the site.
How-to Guides →Enforce TLS-only access with an S3 bucket policy
Attach a bucket policy that denies requests made without TLS, using the @swamp/aws/s3/bucket-policy behavior with a PolicyDocument passed as JSON on creation.
How-to Guides →Provision an S3 bucket for the Swamp datastore
Create a private, versioned S3 bucket and least-privilege IAM policy that @swamp/s3-datastore needs, using the provisioner from @swamp/s3-datastore-bootstrap.
How-to Guides →Amazon S3 extensions
Every Swamp extension for Amazon S3: behavior types, global arguments, methods, vault configuration and the data each one writes, read from the registry.
Reference →Understanding Amazon S3 automation in Swamp
How S3 buckets, policies and access points map to Swamp behaviors and state, and when to use S3 as a resource you manage versus the datastore Swamp uses.
Explanation →