0
0
AWScloud~5 mins

Buckets and objects concept in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to store files or data in the cloud, you use buckets and objects. Buckets are like folders, and objects are the files inside them. This helps you keep your data safe and easy to find.
When you want to save photos or videos online to access them from anywhere.
When you need to back up important documents automatically to the cloud.
When you want to share files with friends or coworkers securely.
When you run a website and need to store images or files for visitors.
When you want to keep logs or data from your app in a safe place.
Commands
This command creates a new bucket named 'example-bucket-12345' in your AWS account. Buckets are containers for your files.
Terminal
aws s3 mb s3://example-bucket-12345
Expected OutputExpected
make_bucket: example-bucket-12345
This command uploads the file 'sample-file.txt' from your computer to the bucket you just created. The file becomes an object inside the bucket.
Terminal
aws s3 cp sample-file.txt s3://example-bucket-12345/
Expected OutputExpected
upload: ./sample-file.txt to s3://example-bucket-12345/sample-file.txt
This command lists all objects (files) inside the bucket so you can see what is stored there.
Terminal
aws s3 ls s3://example-bucket-12345/
Expected OutputExpected
2024-06-01 12:00:00 1234 sample-file.txt
This command deletes the object named 'sample-file.txt' from the bucket, removing the file from cloud storage.
Terminal
aws s3 rm s3://example-bucket-12345/sample-file.txt
Expected OutputExpected
delete: s3://example-bucket-12345/sample-file.txt
This command removes the bucket named 'example-bucket-12345'. The bucket must be empty before you delete it.
Terminal
aws s3 rb s3://example-bucket-12345
Expected OutputExpected
remove_bucket: example-bucket-12345
Key Concept

If you remember nothing else from this pattern, remember: buckets hold your files, and objects are the files inside buckets.

Common Mistakes
Trying to delete a bucket that still has files inside.
AWS does not allow deleting buckets that are not empty, so the command fails.
First delete all objects inside the bucket, then delete the bucket.
Using a bucket name that is already taken by someone else.
Bucket names must be unique across all AWS users, so creation fails if the name is taken.
Choose a unique bucket name, often by adding random numbers or your company name.
Uploading a file without specifying the correct bucket path.
The file may upload to the wrong location or fail if the bucket does not exist.
Double-check the bucket name and path before uploading files.
Summary
Create a bucket to hold your files using 'aws s3 mb'.
Upload files as objects into the bucket using 'aws s3 cp'.
List files inside the bucket with 'aws s3 ls'.
Delete files with 'aws s3 rm' before removing the bucket.
Remove the empty bucket using 'aws s3 rb'.