Step-by-step guide to create a s3 bucket and upload a file and put permission using aws cli

Here’s a full step-by-step guide to:

  1. Create an IAM user in AWS
  2. Set up AWS CLI on a Windows computer
  3. Create a Python virtual environment and install boto3
  4. Create an S3 bucket
  5. Upload a file
  6. Set permissions using AWS CLI

πŸ§‘β€πŸ’» Step 1: Create an IAM User (from AWS Console)

  1. Go to the IAM Console
  2. Click Users > Add users
  3. Set User name: e.g., aws-cli-user
  4. Check Programmatic access
  5. Click Next: Permissions
  6. Attach policies:
    • Choose Attach existing policies directly
    • Select AmazonS3FullAccess
  7. Click Next > Create user
  8. Download or copy:
    • Access key ID
    • Secret access key

βš™οΈ Step 2: Install and Configure AWS CLI on Windows

  1. Download AWS CLI from: https://aws.amazon.com/cli/
  2. Install it and open Command Prompt
  3. Run: bashCopyEditaws configure
  4. Enter the credentials from IAM:
    • AWS Access Key ID
    • AWS Secret Access Key
    • Region (e.g., us-east-1)
    • Output format (e.g., json)

🐍 Step 3: Create Python Virtual Environment & Install boto3

  1. Open Command Prompt in your project directory.
  2. Run: bashCopyEditpython -m venv venv .\venv\Scripts\activate pip install boto3

☁️ Step 4: Create an S3 Bucket Using AWS CLI

S3 bucket names must be globally unique.

aws s3api create-bucket --bucket my-unique-bucket-name-123 --region us-east-1

For other regions:

aws s3api create-bucket --bucket my-unique-bucket-name-123 --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2

πŸ“ Step 5: Upload a File to the S3 Bucket

aws s3 cp myfile.txt s3://my-unique-bucket-name-123/

πŸ” Step 6: Set Permissions (Make Public or Set Bucket Policy)

Option 1: Make the object public

aws s3api put-object-acl --bucket my-unique-bucket-name-123 --key myfile.txt --acl public-read

Option 2: Add a bucket policy (e.g., allow public read to all files in the bucket)

Create a file bucket-policy.json:

jsonCopyEdit{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::my-unique-bucket-name-123/*"
    }
  ]
}

Apply it:

aws s3api put-bucket-policy --bucket my-unique-bucket-name-123 --policy file://bucket-policy.json
Scroll to Top