How to setup aws cli iam and s3 bucket

How to Set Up AWS CLI and IAM for S3 Bucket Access (Beginner-Friendly Guide)

If you’re building a web or mobile app and want to use AWS S3 to store images, files, or documents, learning how to set up the AWS CLI and IAM is a critical first step.

In this guide, we’ll break it down step-by-step  no prior AWS experience required.

What You’ll Learn

 How to install and configure the AWS CLI
 How to create an IAM user with S3 permissions
 How to connect the CLI to your IAM user
 How to test S3 access using CLI commands

Step 1: Install the AWS CLI

The AWS CLI (Command Line Interface) allows you to control AWS from your terminal.

Navitagate to this URL https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html then scroll to AWS CLI install and update instructions

For installation instructions, expand the section for your operating system.

You will see 3 Operating Systems MacOS, Linux and Windows.

In this tutorial we going to focus on the installion on the MacOS.  When u click on the MacOS panel u will the instructions Install and update requirements and Install or update the AWS CLI

On Install or update the AWS CLI

You are going to see 3 Horizonal tabs with labels GUI installer, Command line Installer – all users and Command line – Current user. 

So we going to go with the Gui Installer you follow the process by downloading with this link In your browser, download the macOS pkg file: https://awscli.amazonaws.com/AWSCLIV2.pkg  and once its is downloaded. Open the pkg file and follow the prompt to install the AWS Cli. 

Step 2: Create an IAM User in AWS

  1. Go to IAM Console

  2. Click Users > Add user

  3. Username: my-s3-user

  4. Select Programmatic access

  5. Click Next: Permissions

  6. Choose Attach policies directly

  7. Search for and select: AmazonS3FullAccess (or custom policy — see below)

Optional (Best Practice): Create a custom policy that limits access to one bucket only.

Example Custom IAM Policy (Write Access to One Bucket)

 
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:GetObject"],
"Resource": "arn:aws:s3:::my-app-bucket/*"
}
]
}

Apply this if you want more control over your app’s security.

Step 3: Save Access Credentials

After creating the user:

  • AWS will give you an Access Key ID and a Secret Access Key

  • Copy and save these securely (you won’t see the secret again!)

Step 4: Configure the AWS CLI with IAM Credentials

Open your terminal and type

aws configure

You’ll be prompted for:

AWS Access Key ID: xxxxxxxxxxxxxxxxx
AWS Secret Access Key: xxxxxxxxxxxxxxxxxxxxx
Default region name [e.g. us-east-1]: us-east-1
Default output format [json]: json
 

This saves your credentials to ~/.aws/credentials.

Step 5: Test S3 Access from the CLI

Upload a file:
 
aws s3 cp my-image.jpg s3://my-app-bucket/uploads/my-image.jpg
 
Download a file:
 
aws s3 cp s3://my-app-bucket/uploads/my-image.jpg ./downloaded.jpg
 
List files:
aws s3 ls s3://my-app-bucket/uploads/

 

 Best Practices for IAM + AWS CLI

Best PracticeWhy It Matters
Don’t use root account credentialsToo powerful, not secure
Use separate IAM users for each appEasier to track and revoke
Limit access to only what’s neededFollows the “least privilege” rule
Rotate keys regularlyReduces risk if exposed
Use IAM roles for servers/appsMore secure than hardcoding keys

 Recap

Now you know how to:

  • Install and set up AWS CLI

  • Create a secure IAM user

  • Grant S3 access via policy

  • Upload and download files via the CLI

With this foundation, you can easily integrate S3 into your web, mobile, or backend app securely.

Related reads:

External resources:

 

Leave a Comment

Your email address will not be published. Required fields are marked *