Skip to main content

Insures a unique S3 bucket exists for the account

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

s3_unique_bucket-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file s3_unique_bucket-0.1.0.tar.gz.

File metadata

  • Download URL: s3_unique_bucket-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for s3_unique_bucket-0.1.0.tar.gz
Algorithm Hash digest
SHA256 82f3d4aa206f77cfca79a3bf2a87e5ad54dbe7e91c881f2302d39e2075e11df9
MD5 cef453837f19af53c96e1dd84fa0dbdf
BLAKE2b-256 abd41723bbe4564444b5555b63fe9f4365e79045246be36fdc9e52c0237b65f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page