14. Amazon S3: Buckets, Objects, Policies and Presigned URLs
14.2 Creating a Bucket and Uploading Objects
Aadhi console madhun, mag CLI ne – donhi yayla pahijet. Console chi UI vela-velela badalte, pan settings chi naave tich rahtat.
Console steps
- Open the AWS Console → S3 → Create bucket.
- Bucket type: General purpose. Bucket name:
ravindra-demo-files-pune(lowercase, numbers and hyphens only, 3–63 characters). - AWS Region:
Asia Pacific (Mumbai) ap-south-1. - Object Ownership: keep ACLs disabled (recommended) – access is controlled only by policies.
- Block Public Access settings: keep Block all public access ticked.
- Bucket Versioning: Enable (we will see why in 14.5).
- Default encryption: SSE-S3 (Amazon S3 managed keys) – on by default.
- Click Create bucket, open it and use Upload → Add files → Upload.
AWS CLI steps (on your laptop with aws configure done, or on EC2 with an IAM role – see 14.7):
aws --version # AWS CLI v2 is preinstalled on Amazon Linux 2023
aws s3 mb s3://ravindra-demo-files-pune --region ap-south-1 # make bucket
echo "Namaskar mitrano" > hello.txt
aws s3 cp hello.txt s3://ravindra-demo-files-pune/notes/hello.txt
aws s3 ls s3://ravindra-demo-files-pune/ --recursive --human-readable
aws s3 cp s3://ravindra-demo-files-pune/notes/hello.txt ./copy.txt # download
aws s3 sync ./site s3://ravindra-demo-files-pune/site/ # upload a whole folder
aws s3 rm s3://ravindra-demo-files-pune/notes/hello.txt # delete one object
aws s3api head-object --bucket ravindra-demo-files-pune --key site/index.html # metadata
| Command | What it does |
|---|---|
aws s3 mb / aws s3 rb |
Make / remove a bucket (rb --force also deletes objects – careful!) |
aws s3 cp |
Copy one file to/from S3 (--recursive for folders) |
aws s3 sync |
Copy only new/changed files; --delete removes extra files at the target |
aws s3 ls |
List buckets or objects |
aws s3 mv / aws s3 rm |
Move / delete objects |
aws s3api ... |
Low-level API calls (policies, versioning, head-object, etc.) |
Ravindra Bagale's Tip
The command aws s3 sync ./site s3://bucket/ --delete is very powerful – if the local folder is wrong (for example an empty folder), all the data in the bucket gets deleted! Many students have made this mistake. First add --dryrun to see what will happen, then run the real command.
Ravindra Bagale's Tip – मराठी
aws s3 sync ./site s3://bucket/ --delete हा command खूप powerful आहे – local folder चुकीचा असला (जसं रिकामा folder) तर bucket मधला सगळा data delete होतो! बऱ्याच students नी अशी चूक केली आहे. आधी --dryrun लावून बघा काय होणार आहे, मग खरा command चालवा.
Ravindra Bagale's Tip – हिंदी
aws s3 sync ./site s3://bucket/ --delete command बहुत powerful है – local folder गलत हुआ (जैसे ख़ाली folder) तो bucket का सारा data delete हो जाता है! बहुत से students ने यह गलती की है. पहले --dryrun लगाकर देखो क्या होने वाला है, फिर असली command चलाओ.
Lab
Create a bucket in ap-south-1 from the console, upload one image, then use the CLI to list it, download it with a new name, and upload a folder of three files with aws s3 sync --dryrun followed by the real sync.