How to Configure AWS CLI with Access Keys and Region (Step-by-Step Guide)

How to Configure AWS CLI with Access Keys and Region (Step-by-Step Guide)

AI Reading

Quick summary of this article

The article provides a step-by-step guide on configuring the AWS Command Line Interface (CLI) with access keys and a default region. This setup is necessary before you can use the CLI to push Docker images to Amazon ECR or manage other AWS resources from your terminal. The process involves running the aws configure command and entering four specific pieces of information obtained from your AWS Management Console.

  • You need an AWS Access Key ID and a Secret Access Key. Create these in the IAM service under your user's "Security credentials" tab. Copy the secret key immediately, as it will not be shown again.
  • The Default Region Name sets the AWS data center for your commands. For example, use ap-south-1 for Mumbai, India, or us-east-1 for North Virginia, USA.
  • For the Default Output Format, it is recommended to type json for machine-readable results.
  • After configuration, your credentials are saved securely in the ~/.aws/credentials file on your system.

🪜 Step 8: Configure AWS CLI (Get and Set Up Your Access Keys)

Before pushing your Docker image to AWS (like Amazon ECR), you must configure the AWS CLI on your Ubuntu or WSL terminal.

When you run:

aws configure

You’ll be prompted to enter four details — here’s what each one means and how to get them 👇


🧩 1️⃣ AWS Access Key ID

  • This is your public key that identifies your AWS account.
  • You can find or create it from your AWS Management Console:

Steps:

  1. Log in to your AWS Console.
  2. Go to the IAM (Identity and Access Management) service.
  3. Click Users → select your username.
  4. Under the Security credentials tab, find the section named Access keys.
  5. Click Create access key.
  6. You’ll get:
    • Access key ID (looks like AKIAxxxxxxxxxxxxxx)
    • Secret access key (keep it private!)

⚠️ Important: Copy and store both keys securely (e.g., in a password manager). You won’t be able to see the secret key again later.


🧩 2️⃣ AWS Secret Access Key

  • This is your private key used to authenticate commands.
  • You’ll get it only once when you create the key in IAM.
  • Never share it publicly or commit it to GitHub!

When prompted in your terminal, paste it carefully.


🧭 3️⃣ Default Region Name

This tells AWS which data center region you’ll use by default.

For example:

  • ap-south-1 → Mumbai (India)
  • us-east-1 → North Virginia (USA)
  • eu-west-1 → Ireland

✅ If you’re in India, type:

ap-south-1

📦 4️⃣ Default Output Format

This defines how AWS CLI shows results in your terminal.

You can choose:

  • json → machine-readable format (recommended)
  • text → plain text
  • table → table-style output

✅ Type:

json

✅ Example

Here’s what a complete setup looks like:

$ aws configure
AWS Access Key ID [None]: AKIAEXAMPLE12345
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: ap-south-1
Default output format [None]: json

After this, your credentials are saved in:

~/.aws/credentials

🎯 That’s It!

Your AWS CLI is now configured and ready to:

  • Push Docker images to Amazon ECR
  • Deploy apps to EC2
  • Manage AWS resources directly from your terminal!

 

Leave a Reply

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