Skip to main content

GETTING STARTED WITH AMAZON S3 IN SWAMP

In this tutorial, we will pull the Swamp extension for Amazon S3, define a private bucket with versioning enabled as a Swamp behavior, and create that bucket in an AWS account.

What we will build

We will build a behavior named assets-bucket of type @swamp/aws/s3/bucket. It describes a bucket in us-east-1 with versioning enabled and all four public access block settings turned on. When we run its create method, Swamp creates the bucket in AWS and records the bucket's state in the repository.

Prerequisites

Pull the S3 extension

The S3 behavior types come from the @swamp/aws/s3 extension. First, we pull it into the repository:

swamp extension pull @swamp/aws/s3 --yes

You will see output like:

INF extension·pull: Pulling "@swamp/aws/s3"@"2026.10.13.1"
INF extension·pull: Identity verified: "@swamp/aws/s3"@"2026.10.13.1"
INF extension·pull: Pulled "@swamp/aws/s3"@"2026.10.13.1"
INF extension·pull: Extracted 24 files:

The repository now has the @swamp/aws/s3/bucket type and the other S3 types, such as @swamp/aws/s3/bucket-policy and @swamp/aws/s3/access-point.

Define the bucket

Now we create a behavior named assets-bucket of type @swamp/aws/s3/bucket. Create and Run a Behavior shows how to create a behavior and edit its definition. We give it these global arguments:

globalArguments:
  BucketName: example-swamp-assets
  region: us-east-1
  VersioningConfiguration:
    Status: Enabled
  PublicAccessBlockConfiguration:
    BlockPublicAcls: true
    IgnorePublicAcls: true
    BlockPublicPolicy: true
    RestrictPublicBuckets: true

Bucket names are unique across all of AWS, so we replace example-swamp-assets with a name of our own before going further.

Notice that VersioningConfiguration and PublicAccessBlockConfiguration are objects, not plain strings. Each one maps to a setting on the bucket. None of the bucket type's global arguments are required, so the definition contains only the settings we want.

Create the bucket in AWS

Now we run the behavior's create method:

swamp behavior run assets-bucket create

This command reads AWS credentials from the default credential chain and creates the bucket in us-east-1 with versioning enabled and public access blocked. It then writes the S3 Bucket resource state into the repository's data. When the run finishes, the bucket appears in the S3 console under the name we chose. Query and Manage Data shows how to find the state that Swamp recorded.

What we built

We pulled the @swamp/aws/s3 extension and defined a bucket as a Swamp behavior, with versioning and the public access block as global arguments. Running its create method created the bucket in AWS and recorded the bucket's resource state in the repository.