Home/Engineer/Cloud/Creating AWS S3 Buckets and …
CloudBeginnerubuntumacosawss3cli

Creating AWS S3 Buckets and Using the CLI

How to create an S3 bucket, configure bucket policies and ACLs, and upload, download, and sync files with the AWS CLI.

Contents
  1. Creating an S3 Bucket
  2. Uploading / Downloading Files
  3. Useful Options
  4. Bucket Policy (Public Read)
  5. Static Website Hosting
  6. Automated Backups (cron + S3)

Creating an S3 Bucket

Bash
aws s3 mb s3://my-bucket-name --region ap-northeast-2
aws s3 ls
aws s3 ls s3://my-bucket-name/
aws s3 ls s3://my-bucket-name/logs/ --recursive

Uploading / Downloading Files

Bash
aws s3 cp file.txt s3://my-bucket/file.txt
aws s3 cp ./dist/ s3://my-bucket/dist/ --recursive

aws s3 cp s3://my-bucket/file.txt ./file.txt

aws s3 sync ./dist/ s3://my-bucket/ --delete
aws s3 sync s3://my-bucket/backups/ ./backups/

Useful Options

Bash
aws s3 sync . s3://my-bucket/ --exclude "*.log" --exclude ".git/*"

aws s3 cp backup.tar.gz s3://my-bucket/backups/ \
  --storage-class STANDARD_IA

# Presigned URL (1 hour)
aws s3 presign s3://my-bucket/private.pdf --expires-in 3600

Bucket Policy (Public Read)

JSON
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::my-bucket/*"
  }]
}
Bash
aws s3api put-bucket-policy \
  --bucket my-bucket \
  --policy file://bucket-policy.json

Static Website Hosting

Bash
aws s3 website s3://my-bucket/ \
  --index-document index.html \
  --error-document error.html

Automated Backups (cron + S3)

Bash
#!/bin/bash
DATE=$(date +%Y%m%d-%H%M)
BACKUP_FILE="/tmp/db-backup-${DATE}.tar.gz"

pg_dump mydb | gzip > "$BACKUP_FILE"
aws s3 cp "$BACKUP_FILE" "s3://my-backups/db/${DATE}.tar.gz" \
  --storage-class STANDARD_IA
rm -f "$BACKUP_FILE"
Bash
# crontab
0 3 * * * /opt/scripts/backup-to-s3.sh >> /var/log/s3-backup.log 2>&1
#aws#s3#cli#cloud
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Topic-related official docs (auto-linked · not per-claim sources)AWS documentation ↗web.dev Core Web Vitals ↗

Questions & answers

Ask a question about this guide. We'll review and reply.