Public Bucket
Sometimes you want to share your bucket with the world. You can do this by creating a public bucket. This will allow anyone to read the contents of your bucket. You can still control who can write to your bucket.
Creating a public bucket using AWS CLI
Assuming you have the AWS CLI configured as shown in the AWS CLI guide, you can create a public bucket as follows:
aws s3api --endpoint-url https://t3.storage.dev create-bucket --bucket foo-public-bucket --acl public-read
$ aws s3api --endpoint-url https://t3.storage.dev create-bucket --bucket foo-public-bucket --acl public-read
{
"Location": "/foo-public-bucket"
}
The key here is the --acl public-read
flag. This will allow anyone to read the
contents of the bucket foo-public-bucket
.
Accessing objects in a public bucket
Objects in a public bucket (by default) can be read without any authentication. However, only those with access to the bucket can write objects.
Let's upload a file to our public bucket:
$ aws s3api --endpoint-url https://t3.storage.dev put-object --bucket foo-public-bucket --key bar.txt --body bar.txt
{
"ETag": "\"c157a79031e1c40f85931829bc5fc552\""
}
Now, anyone can read this file without authentication.