Skip to content

s3

Source: builtin/s3

Amazon S3, S3-compatible object stores (MinIO, R2, LocalStack), and Google Cloud Storage.

Provider configuration

NameTypeRequiredDefaultDescription
access_key_idstringno—Static access key (an HMAC key with gcs). Set with secret_access_key.
endpointstringno—Base URL of an S3-compatible store, such as http://localhost:9000 for MinIO.
gcsboolnofalseTalk to Google Cloud Storage, with Application Default Credentials unless HMAC keys are set.
path_styleboolnofalseAddress buckets as host/bucket rather than bucket.host. MinIO and LocalStack usually need true.
profilestringno—Shared-config profile to use instead of AWS_PROFILE.
projectstringno—Google Cloud project for new buckets. Only with gcs.
regionstringno—Region for requests and new buckets. Defaults to us-east-1, or auto with gcs. R2 uses auto.
secret_access_keystringno—Static secret key. Pass it through a variable or env().
session_tokenstringno—Session token for temporary static credentials.

Actions

s3_create_bucket

Create a bucket. With exists_ok (the default), a bucket you already own is used as it is, with created = false. A name someone else owns is an error.

Make sure a local MinIO has the uploads bucket.

action "s3_create_bucket" "uploads" {
  bucket = "app-uploads"
}

Attributes

NameTypeRequiredDefaultDescription
bucketstringyes—Bucket name.
exists_okboolnotrueWhether a bucket that already exists is fine.

Outputs

Type: object({bucket=string,created=bool}).

FieldTypeDescription
bucketstringThe bucket name.
createdboolWhether the action created it.

s3_delete_bucket

Delete an empty bucket.

Attributes

NameTypeRequiredDefaultDescription
bucketstringyes—Bucket name.

Outputs

Type: object({}).

None.

s3_delete_object

Delete an object. Deleting one that doesn’t exist succeeds.

Attributes

NameTypeRequiredDefaultDescription
bucketstringyes—Bucket name.
keystringyes—Object key.

Outputs

Type: object({}).

None.

s3_put_object

Upload an object from inline text, base64, or a file next to the scenario. Set exactly one of content, content_base64 and file. Files are streamed, not read into memory.

Upload an avatar for a seeded user and store its key on the row.

action "s3_put_object" "avatar" {
  bucket = action.s3_create_bucket.uploads.bucket
  key    = "avatars/${action.postgres_insert.user.id}.png"
  file   = "./fixtures/avatar.png"
}

action "postgres_update" "user_avatar" {
  table = "users"
  set   = { avatar_key = action.s3_put_object.avatar.key }
  where = { id = action.postgres_insert.user.id }
}

Attributes

NameTypeRequiredDefaultDescription
bucketstringyes—Bucket name.
contentstringno—Object content as text.
content_base64stringno—Object content, base64-encoded, for small binaries.
content_typestringno—Content type. Defaults to one guessed from the key’s extension, then application/octet-stream.
filestringno—Path to a file to upload, relative to the scenario file.
keystringyes—Object key.
metadatamap(string)no—User metadata (x-amz-meta-*).
on_conflictstringno"update"What to do when the object already exists: "update" overwrites it, "ignore" leaves it and returns its etag and size.

Outputs

Type: object({bucket=string,created=bool,etag=string,key=string,size=number}).

FieldTypeDescription
bucketstringThe bucket name.
keystringThe object key.
etagstringThe object’s ETag, without quotes.
sizenumberSize in bytes.
createdboolWhether the object was new.

Notes

  • Credentials come from the standard AWS chain unless set in the config: environment variables, AWS_PROFILE and shared config (SSO included), web identity, and container and instance roles.
  • With gcs = true the provider talks to Google Cloud Storage’s XML API and authenticates with Application Default Credentials (gcloud auth application-default login, a service-account key file, or workload identity). Set access_key_id and secret_access_key to use HMAC keys instead.
  • orchard teardown undoes the actions automatically, unless an action has its own lifecycle { teardown { } } block or sets lifecycle { managed_teardown = false }. A bucket or object the scenario created is deleted. Before overwriting an object, s3_put_object copies it to .orchard-backup/<run>/<key> in the same bucket; teardown copies it back when an earlier action in the run created the object, or with managed_teardown = true, and deletes the backup either way. Other overwritten objects are left as written. Without automatic teardown the backup stays in the bucket.
  • Buckets are deleted only when empty, so objects the scenario didn’t create keep a created bucket alive through teardown.