Skip to main content

s3-unique-bucket

Utility to create a unique bucket for each S3 account, useful for deployment scenarios.

Did you ever need a bucket to upload your deployment templates into? Are you always annoyed by having to create them manually, not really making your deployment pipeline truly automatic? Well, worry no more!

This script is an easy and idempotent way to just create an S3 bucket that will have a very high chance to avoid name conflicts. If run a second time, the script recognizes the bucket already exists and will only emit the bucket's name for reuse.

Example

bucket=$(s3-unique-bucket)
aws s3 cp foo.txt s3://$bucket/foo.txt

How it works

The bucket name is generated from a user-settable prefix, the sha1 hash of the account ID with base32 encoding, and the region the bucket is created in. Then the script checks if a bucket with this name exists on the provided account. If not, it is created. Then finally the name of the bucket is emitted via stdout.

Documentation

Set the AWS credentials and region with environment variables.

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_DEFAULT_REGION

The rest is configured with command line arguments.

-p/--prefix: User-settable prefix (OPTIONAL)

Default: account-bucket

The bucket name starts with this settable prefix. It can also be empty. Note that a dash ('-') is automatically added between the prefix and the hash if prefix is not empty.

-p/--prefix: AWS Account Region (CONDITIONAL)

Condition: Must be provided if environment variable AWS_DEFAULT_REGION isn't set.

Which region the bucket shall be created in.

Release files for s3-unique-bucket 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for s3-unique-bucket 0.1.0
File Size Uploaded
s3_unique_bucket-0.1.0.tar.gz 3.0 kB Details

Release files / s3_unique_bucket-0.1.0.tar.gz

Download URL s3_unique_bucket-0.1.0.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
82f3d4aa206f77cfca79a3bf2a87e5ad54dbe7e91c881f2302d39e2075e11df9
BLAKE2b-256 checksum
How to use checksums
abd41723bbe4564444b5555b63fe9f4365e79045246be36fdc9e52c0237b65f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page