Bootstrap FreeKB - Amazon Web Services (AWS) - Create S3 Bucket using the AWS CLI
Amazon Web Services (AWS) - Create S3 Bucket using the AWS CLI


This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.

An S3 Bucket is similar to an NFS share in that it is a mountable storage volume.

The aws s3api create-bucket command can be used to create an S3 Bucket. Your S3 Bucket name must be unique in the region. For example, let's say you try to create a bucket named my-bucket in the us-east-1 region. This will return something like bucket name is not available because there is already an S3 Bucket in the us-east-1 region named my-bucket.

~]$ aws s3api create-bucket --bucket my-bucket --region us-east-1

An error occurred (BucketAlreadyExists) when calling the CreateBucket operation: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.

 

One simple option is to include a random string in the bucket name.

aws s3api create-bucket --bucket my-bucket-abcdefg --region us-east-1

 

By default, S3 Buckets are created in the us-east-1 region. --create-bucket-configuration LocationConstraint can be used if you want to create the S3 Bucket in some other region.

aws s3api create-bucket --bucket my-bucket-abcdefg --region us-east-2 --create-bucket-configuration LocationConstraint=us-east-2

 

The aws s3api put-bucket-tagging command can be used to create tags.

aws s3api put-bucket-tagging --bucket my-bucket-abcdefg --tagging '{"TagSet":[{"Key":"environment","Value":"staging"}]}'

 

And then the aws s3api get-bucket-tagging command can be used to return an S3 Buckets tags.

~]# aws s3api get-bucket-tagging --bucket my-bucket-abcdefg
{
    "TagSet": [
        {
            "Key": "environment",
            "Value": "staging"
        }
    ]
}

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 3ae37b in the box below so that we can be sure you are a human.