Day 54: AWS CLI & Creating an S3 Bucket

🧠 What is AWS CLI?

The AWS Command Line Interface (CLI) is a powerful tool that allows you to manage AWS services directly from your terminal.

✅ Benefits:

  • Automate tasks

  • Integrate with CI/CD

  • Script infrastructure provisioning

  • Manage AWS from Linux, macOS, or Windows


⚙️ Step 1: Install AWS CLI

On Linux:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

On Windows or macOS:

Visit AWS CLI installation docs


⚙️ Step 2: Configure AWS CLI

Once installed, run:

aws configure

You’ll be prompted to enter:

  • Access Key ID

  • Secret Access Key

  • Default region (e.g., us-east-1)

  • Output format (e.g., json or yaml)

You can find credentials in the IAM section of AWS console (create a user with programmatic access).


🗂️ Step 3: Create an S3 Bucket via CLI

Let’s create a bucket named my-devops-demo-bucket in us-east-1:

aws s3 create-bucket \
  --bucket my-devops-demo-bucket \
  --region us-east-1 \
  --create-bucket-configuration LocationConstraint=us-east-1

📝 Note: For us-east-1, AWS allows simpler creation:

aws s3 create-bucket --bucket my-devops-demo-bucket

📤 Step 4: Upload a File to S3 Bucket

Let’s upload a file named index.html:

aws s3 cp index.html s3://my-devops-demo-bucket/

🌍 Step 5: Make the File Public (Optional)

Create a public-read ACL:

aws s3 put-object-acl \
  --bucket my-devops-demo-bucket \
  --key index.html \
  --acl public-read

🌐 Step 6: Host a Static Website

Enable static site hosting:

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

The static website will be available at:

http://my-devops-demo-bucket.s3-website-us-east-1.amazonaws.com

🧹 Bonus: Delete a Bucket

aws s3 rb s3://my-devops-demo-bucket --force

📦 Summary

TaskAWS CLI Command
Configure AWSaws configure
Create Bucketaws s3api create-bucket
Upload Fileaws s3 cp <file> s3://<bucket-name>/
Make File Publicaws s3api put-object-acl
Host Static Websiteaws s3 website
Remove Bucketaws s3 rb s3://<bucket-name> --force
0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir