AWS Builder Center
Setting Up Amazon S3 Storage: Your First Bucket Without the Surprise Bill

Setting Up Amazon S3 Storage: Your First Bucket Without the Surprise Bill

Create a private S3 bucket, upload and share files safely, set a budget alert, automate cleanup and delete everything when you're done. Amazon S3 is one of the first services most AWS learners touch, and for good reason: it's simple, durable and flexible. But simple doesn't mean free of consequences. Storage, requests and data transfer all show up on a bill.

Start Small: Understand the Building Blocks

S3 stores data as objects inside buckets.
  • Bucket: A container for objects. Its name must be globally unique across AWS, and it lives in the Region you choose.
  • Object: The data you store (a file, an image, a log) plus its metadata.
  • Key: The unique name of an object inside a bucket, such as demo/hello.txt

Create Your First Bucket

In the AWS console:
  1. Sign in, choose your Region from the top-right menu and open S3.
  2. Choose Create bucket.
  3. Keep the General purpose bucket type and enter a globally unique name (3 to 63 characters: lowercase letters, numbers and hyphens).
  4. Leave Block all public access turned on.
  5. Leave ACLs disabled (the default Bucket owner enforced setting).
  6. Leave default encryption on its default setting (SSE-S3).
  7. Leave Versioning disabled for now. We'll come back to it.
  8. Choose Create bucket.
Console layouts and defaults change over time, so compare what you see with the current documentation.
Prefer the terminal? The AWS CLI equivalent:
1
2
BUCKET="s3-challenge-$RANDOM$RANDOM"
aws s3 mb s3://$BUCKET --region us-east-1
Replace the Region with the one you chose. The random suffix helps avoid name collisions, since bucket names are shared across all AWS accounts.

Upload and Download Your First Object

Create a tiny test file, upload it, list it and download it again:
1
2
3
4
5
echo "Hello, S3!" > hello.txt

aws s3 cp hello.txt s3://$BUCKET/demo/hello.txt
aws s3 ls s3://$BUCKET/demo/
aws s3 cp s3://$BUCKET/demo/hello.txt downloaded.txt
You can do the same in the console with Upload and Download.

Keep It Private, Share It Safely

The most common S3 mistake isn't a big bill. It's an accidentally public bucket.
Block Public Access is your safety net. Confirm it's active:
1
aws s3api get-public-access-block --bucket $BUCKET
All four settings should report true.
Need to share one file with someone? Don't make the bucket public. Generate a presigned URL instead:
1
aws s3 presign s3://$BUCKET/demo/hello.txt --expires-in 300
This creates a link that works for 300 seconds. Treat it like a password: anyone who has the link can access that object until it expires, so keep the expiration short.

Set a Budget Alert Before You Upload More

Before you move beyond a hello-world file, set up monitoring.
AWS Budgets lets you define a cost budget and send notifications when spending reaches a threshold or is forecast to exceed it. A small monthly budget with a couple of alert thresholds is plenty for a learning account.

Know What Can Cost Money

AWS now offers new customers promotional credits and a choice between a Free account plan and a Paid account plan. The Free plan is meant for experimentation, and it ends after a limited period or when credits run out. The Paid plan gives broader service access, but usage can incur standard charges once credits don't apply.
Remember: credits are not a guarantee that every service or feature is free. Check your own account's plan, credits and current pricing. Existing accounts may have different terms.

Automate Cleanup With a Lifecycle Rule

Forgotten files are the quiet way S3 costs creep up. A lifecycle rule can delete old objects for you.
Create a file named lifecycle.json:
1
2
3
4
5
6
7
8
9
10
11
12
{
"Rules": [
{
"ID": "expire-demo-objects",
"Status": "Enabled",
"Filter": { "Prefix": "demo/" },
"Expiration": { "Days": 30 },
"NoncurrentVersionExpiration": { "NoncurrentDays": 30 },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
}
]
}
Apply it to your bucket:
1
2
3
aws s3api put-bucket-lifecycle-configuration \
--bucket $BUCKET \
--lifecycle-configuration file://lifecycle.json
This rule expires objects under demo/ after 30 days, removes old versions if you ever enable versioning and cleans up abandoned multipart uploads after 7 days.

Check What You've Actually Stored

It's easy to lose track of what's in a bucket. Inspect it from the terminal:
1
2
aws s3 ls
aws s3 ls s3://$BUCKET --recursive --human-readable --summarize
The first command lists the buckets in your account. The second lists every object in your bucket and prints the total object count and size.
These commands inspect resources in the configured account. They don't calculate your complete AWS bill, so keep reviewing Billing and Cost Management as well.
Before running any command that deletes things, confirm the account and Region you're working in. Never delete buckets blindly because they may support other applications.

The Cleanup Checklist

When your experiment is finished, take a few minutes to clean up.
  • Verify the AWS account and Region you used.
  • Download anything you want to keep.
  • Empty the bucket. In the console, use Empty, which also removes object versions and delete markers.
  • Delete the bucket.
  • Remove local test files and any presigned links you shared.
  • Review AWS Billing and Cost Management.
  • Keep your budget notifications enabled.
From the CLI, for an unversioned bucket:
1
2
aws s3 rm s3://$BUCKET --recursive
aws s3 rb s3://$BUCKET
A bucket must be empty before it can be deleted. If you enabled versioning, use the console's Empty action so every version and delete marker is removed too.

Conclusion: Take the S3 Challenge!

Setting up S3 doesn't have to be complicated or expensive. Start with a private bucket, understand what you're billed for, automate cleanup and delete what you no longer need.
The real challenge isn't simply spending nothing. It's learning to make informed decisions about cloud storage before costs become a problem.
Your turn: What's one S3 habit that keeps your storage secure and your bill predictable? Have you ever found an old bucket you forgot you had?
Share your experience in the comments. Your lesson might help another AWS learner!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article