General purpose bucket naming rules - Amazon Simple Storage Service

General purpose bucket naming rules

When you create a general purpose bucket, make sure that you consider the length, valid characters, formatting, and uniqueness of bucket names. The following sections provide information about general purpose bucket naming, including naming rules, best practices, and an example for creating a general purpose bucket with a name that includes a globally unique identifier (GUID).

For information about object key names, see Creating object key names.

To create a general purpose bucket, see Creating a general purpose bucket.

General purpose buckets naming rules

The following naming rules apply for general purpose buckets.

Important
  • Bucket names must be unique across all AWS accounts in all of the AWS Regions within a partition. A partition is a grouping of Regions. AWS currently has three partitions: aws (commercial Regions), aws-cn (China Regions), and aws-us-gov (AWS GovCloud (US) Regions).

  • A bucket name can't be used by another AWS account in the same partition until the bucket is deleted. After you delete a bucket, be aware that another AWS account in the same partition can use the same bucket name for a new bucket and can therefore potentially receive requests intended for the deleted bucket. If you want to prevent this, or if you want to continue to use the same bucket name, don't delete the bucket. We recommend that you empty the bucket and keep it, and instead, block any bucket requests as needed. For buckets no longer in active use, we recommend emptying the bucket of all objects to minimize costs while retaining the bucket itself.

  • When you create a general purpose bucket, you choose its name and the AWS Region to create it in. After you create a general purpose bucket, you can't change its name or Region.

  • Don't include sensitive information in the bucket name. The bucket name is visible in the URLs that point to the objects in the bucket.

Note

Before March 1, 2018, buckets created in the US East (N. Virginia) Region could have names that were up to 255 characters long and included uppercase letters and underscores. Beginning March 1, 2018, new buckets in US East (N. Virginia) must conform to the same rules applied in all other Regions.

Example general purpose bucket names

The following bucket names show examples of which characters are allowed in general purpose bucket names: a-z, 0-9, and hyphens (-). The amzn-s3-demo- reserved prefix is used here only for illustration. Because it's a reserved prefix, you can't create bucket names that start with amzn-s3-demo-.

  • amzn-s3-demo-bucket1-a1b2c3d4-5678-90ab-cdef-example11111

  • amzn-s3-demo-bucket

The following example bucket names are valid but not recommended for uses other than static website hosting because they contain periods (.):

  • example.com

  • www.example.com

  • my.example.s3.bucket

The following example bucket names are not valid:

  • amzn_s3_demo_bucket (contains underscores)

  • AmznS3DemoBucket (contains uppercase letters)

  • amzn-s3-demo-bucket- (starts with amzn-s3-demo- prefix and ends with a hyphen)

  • example..com (contains two periods in a row)

  • 192.168.5.4 (matches format of an IP address)

Best practices

When naming your general purpose buckets, consider the following bucket naming best practices.

Choose a bucket naming scheme that's unlikely to cause naming conflicts

If your application automatically creates buckets, choose a bucket naming scheme that's unlikely to cause naming conflicts. Ensure that your application logic will choose a different bucket name if a bucket name is already taken.

Append globally unique identifiers (GUIDs) to bucket names

We recommend that you create bucket names that aren't predictable. Don't write code assuming your chosen bucket name is available unless you have already created the bucket. One method for creating bucket names that aren't predictable is to append a Globally Unique Identifier (GUID) to your bucket name, for example, amzn-s3-demo-bucket-a1b2c3d4-5678-90ab-cdef-example11111. For more information, see Creating a bucket that uses a GUID in the bucket name.

Avoid using periods (.) in bucket names

For best compatibility, we recommend that you avoid using periods (.) in bucket names, except for buckets that are used only for static website hosting. If you include periods in a bucket's name, you can't use virtual-host-style addressing over HTTPS, unless you perform your own certificate validation. The security certificates used for virtual hosting of buckets don't work for buckets with periods in their names.

This limitation doesn't affect buckets used for static website hosting, because static website hosting is available only over HTTP. For more information about virtual-host-style addressing, see Virtual hosting of general purpose buckets. For more information about static website hosting, see Hosting a static website using Amazon S3.

Choose a relevant name

When you name a bucket, we recommend that you choose a name that's relevant to you or your business. Avoid using names associated with others. For example, avoid using AWS or Amazon in your bucket name.

Don't delete buckets so that you can reuse bucket names

If a bucket is empty, you can delete it. After a bucket is deleted, the name becomes available for reuse. However, you aren't guaranteed to be able to reuse the name right away, or at all. After you delete a bucket, some time might pass before you can reuse the name. In addition, another AWS account might create a bucket with the same name before you can reuse the name.

After you delete a general purpose bucket, be aware that another AWS account in the same partition can use the same bucket name for a new bucket and can therefore potentially receive requests intended for the deleted general purpose bucket. If you want to prevent this, or if you want to continue to use the same general purpose bucket name, don't delete the general purpose bucket. We recommend that you empty the bucket and keep it, and instead, block any bucket requests as needed.

Creating a bucket that uses a GUID in the bucket name

The following examples show you how to create a general purpose bucket that uses a GUID at the end of the bucket name.

The following AWS CLI example creates a general purpose bucket in the US West (N. California) Region (us-west-1) Region with an example bucket name that uses a globally unique identifier (GUID). To use this example command, replace the user input placeholders with your own information.

aws s3api create-bucket \ --bucket amzn-s3-demo-bucket1$(uuidgen | tr -d - | tr '[:upper:]' '[:lower:]' ) \ --region us-west-1 \ --create-bucket-configuration LocationConstraint=us-west-1

The following example shows you how to create a with a GUID at the end of the bucket name in US East (N. Virginia) Region (us-east-1) by using the AWS SDK for Java. To use this example, replace the user input placeholders with your own information. For information about other AWS SDKs, see Tools to Build on AWS.

import com.amazonaws.regions.Regions; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.model.Bucket; import com.amazonaws.services.s3.model.CreateBucketRequest; import java.util.List; import java.util.UUID; public class CreateBucketWithUUID { public static void main(String[] args) { final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build(); String bucketName = "amzn-s3-demo-bucket" + UUID.randomUUID().toString().replace("-", ""); CreateBucketRequest createRequest = new CreateBucketRequest(bucketName); System.out.println(bucketName); s3.createBucket(createRequest); } }