1. Introduction & use cases
Amazon S3 (Simple Storage Service) stores files – called objects – in buckets. It is extremely durable, scales without limits and charges for what you store and transfer. Each object is reached by a key (its path), e.g. uploads/2026/photo.jpg.
Use S3 for user uploads, backups, logs, build artifacts and data lakes, and – together with CloudFront – for hosting static websites. New buckets block public access by default; share files with presigned URLs or through CloudFront instead of making buckets public.
Where it is used
- User uploads (images, documents) for web/mobile apps
- Backups and archives (with cheaper storage classes)
- Static websites and SPA hosting behind CloudFront
- CI artifacts, logs and data for analytics
2. Prerequisites
| You need | Version / notes |
|---|---|
| AWS account | With MFA on the root user and a non-root admin identity |
| AWS CLI v2 | Installed and configured – see the AWS guide |
| Node.js LTS | For the SDK example |
3. Local setup
1Create a bucket
Names are global and DNS-safe (lowercase, numbers, hyphens). Keep Block Public Access on.
BASHaws s3 mb s3://my-app-uploads-2026 --region ap-south-1 aws s3api get-public-access-block --bucket my-app-uploads-20262Upload, list and download
synccopies only changed files – great for deploying folders.BASHaws s3 cp photo.jpg s3://my-app-uploads-2026/images/photo.jpg aws s3 ls s3://my-app-uploads-2026/images/ aws s3 sync ./dist s3://my-app-uploads-2026/site/ --delete aws s3 cp s3://my-app-uploads-2026/images/photo.jpg ./copy.jpg3Share a private file temporarily
A presigned URL works for a limited time without making the object public.
BASHaws s3 presign s3://my-app-uploads-2026/images/photo.jpg --expires-in 3600
4. Create & run a project
1Install the AWS SDK v3 packages
Only install the clients you need.
BASHmkdir s3-demo && cd s3-demo npm init -y && npm pkg set type=module npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner2Upload from Node.js and create a download link
Credentials come from your profile locally and from the IAM role on AWS.
index.jsimport { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3'; import { getSignedUrl } from '@aws-sdk/s3-request-presigner'; import { readFile } from 'node:fs/promises'; const s3 = new S3Client({ region: process.env.AWS_REGION }); const Bucket = process.env.S3_BUCKET; const Key = 'images/hello.jpg'; await s3.send(new PutObjectCommand({ Bucket, Key, Body: await readFile('hello.jpg'), ContentType: 'image/jpeg' })); const url = await getSignedUrl(s3, new GetObjectCommand({ Bucket, Key }), { expiresIn: 600 }); console.log('Uploaded. Link valid for 10 minutes:', url);3Let browsers upload directly (presigned PUT)
Your API creates a presigned
PutObjectCommandURL; the browser uploads the file straight to S3, saving server bandwidth. Allow your site’s origin with a CORS rule: save it ascors.jsonwrapped as{"CORSRules": [ … ]}and apply it withaws s3api put-bucket-cors --bucket my-app-uploads-2026 --cors-configuration file://cors.json.cors.json[ { "AllowedOrigins": ["https://example.com", "http://localhost:5173"], "AllowedMethods": ["GET", "PUT"], "AllowedHeaders": ["*"], "ExposeHeaders": ["ETag"], "MaxAgeSeconds": 3000 } ]4Run it
Use your CLI profile for credentials.
BASHAWS_PROFILE=dev node --env-file=.env index.js
✅ When it works you should see output like Figure 1.
5. Development configuration
Environment variables
AWS_REGION=ap-south-1
S3_BUCKET=my-app-uploads-2026
# locally: AWS_PROFILE=dev · on AWS: IAM roleKey dependencies
| Package / tool | Used for |
|---|---|
@aws-sdk/client-s3 | S3 API for JavaScript (v3, modular) |
@aws-sdk/s3-request-presigner | Presigned URLs |
boto3 | Python SDK |
aws s3 / s3api | CLI commands |
S3 storage classes | Standard, Intelligent-Tiering, Glacier for archives |
Folder structure
my-app-uploads-2026 (bucket)
├── images/
│ └── 2026/12/photo.jpg
├── documents/
├── backups/
└── site/ # static site files (served via CloudFront)Essential commands
| Command | What it does |
|---|---|
aws s3 ls s3://bucket/prefix/ | List objects |
aws s3 cp / mv / rm | Copy, move, delete |
aws s3 sync dir s3://bucket/ --delete | Mirror a folder |
aws s3 presign s3://bucket/key | Temporary link |
aws s3api put-bucket-versioning --bucket b --versioning-configuration Status=Enabled | Keep old versions |
6. Production deployment
Server & hosting requirements
| Requirement | Recommendation |
|---|---|
| Access | Block Public Access ON; access via IAM roles, presigned URLs or CloudFront OAC |
| Least privilege | App role allowed only s3:GetObject/PutObject on its bucket/prefix |
| Protection | Versioning + default encryption (SSE-S3 on by default) |
| Costs | Lifecycle rules to move/delete old data |
| Static site | CloudFront distribution + ACM certificate + DNS |
Deployment steps
1Give your app a least-privilege policy
Attach to the EC2/Lambda/ECS role.
iam-policy.json{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["s3:GetObject", "s3:PutObject"], "Resource": "arn:aws:s3:::my-app-uploads-2026/images/*" }] }2Turn on versioning
Protects against accidental deletes and overwrites.
BASHaws s3api put-bucket-versioning --bucket my-app-uploads-2026 --versioning-configuration Status=Enabled3Add a lifecycle rule
Example: move backups to Glacier after 30 days and delete them after a year; delete old object versions after 30 days. Apply it with
aws s3api put-bucket-lifecycle-configuration --bucket my-app-uploads-2026 --lifecycle-configuration file://lifecycle.json.lifecycle.json{ "Rules": [{ "ID": "backups", "Filter": { "Prefix": "backups/" }, "Status": "Enabled", "Transitions": [{ "Days": 30, "StorageClass": "GLACIER" }], "Expiration": { "Days": 365 }, "NoncurrentVersionExpiration": { "NoncurrentDays": 30 } }] }4Host a static website
Upload the build to a private bucket and serve it through CloudFront with Origin Access Control and HTTPS – step by step in the CloudFront guide.
BASHnpm run build aws s3 sync dist/ s3://my-site-bucket/ --delete
🗺 The whole path from your code to the live site is drawn in the deployment diagram.
7. Images & screenshots
Illustrations drawn for this guide from the commands above. Product dashboards change often, so for screens such as cloud consoles follow the step text and the official documentation.
8. Common errors & solutions
AccessDenied on upload or download
The identity’s policy (or the bucket policy) does not allow the action on that ARN. Check bucket/* vs bucket in the Resource and the region/profile used.
BucketAlreadyExists
Bucket names are global across all AWS accounts. Add a unique suffix.
Browser upload blocked by CORS
Add a CORS rule with your exact origin and the PUT method; presigned URLs also need the same Content-Type that was signed.
SignatureDoesNotMatch with presigned URLs
The request differs from what was signed (method, headers, Content-Type) or the clock is wrong.
Accidentally public data
Keep Block Public Access on at account and bucket level; use CloudFront OAC or presigned URLs instead of public buckets.
Best practices
- Never make buckets public; use CloudFront or presigned URLs.
- One bucket per purpose/environment, with clear prefixes.
- Versioning + lifecycle rules for safety and cost.
- Use IAM roles, not access keys, from AWS compute.
- Set correct
Content-Typeand cache headers when uploading site assets.