Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

AWS CLI Credentials Setup: Configure, Verify, and Secure Access

Originally published on 2015-10-27; fully revised and updated.

This guide explains how to set up AWS credentials for the AWS CLI, verify that access works, and choose the right credential method for local work and automation.

Setup AWS credentials using AWS CLI

Install and verify the AWS CLI

If the AWS CLI is not installed yet, follow your platform-specific installation steps. After install, verify the CLI is available in your shell:

aws --version
aws help

Configure credentials with aws configure

Get an access key ID, secret access key, and preferred default region from your AWS account setup (commonly via IAM). Then run:

aws configure
AWS Access Key ID [None]: YOUR_ACCESS_KEY_ID
AWS Secret Access Key [None]: YOUR_SECRET_ACCESS_KEY
Default region name [None]: us-east-1
Default output format [None]: jsonCode language: CSS (css)

Quick validation commands:

aws sts get-caller-identity
aws s3 lsCode language: JavaScript (javascript)

Where AWS CLI stores credentials and config

By default, AWS CLI stores secrets and settings in separate files. On Linux/macOS/Unix: ~/.aws/credentials and ~/.aws/config. On Windows: C:\Users\USERNAME\.aws\credentials and C:\Users\USERNAME\.aws\config.

cat ~/.aws/credentials
cat ~/.aws/config

# Example ~/.aws/credentials
[default]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY

# Example ~/.aws/config
[default]
region = us-east-1
output = jsonCode language: PHP (php)

Credential methods compared

MethodWhere secrets liveBest forExample
aws configure default profile~/.aws/credentialsSimple single-account local setupaws configure
Named profile~/.aws/credentials under profile nameMultiple AWS accounts/environmentsaws configure --profile dev
Environment variablesShell/process environmentCI jobs and short-lived sessionsexport AWS_ACCESS_KEY_ID=...
Instance or workload roleNo static key in local filesEC2, ECS, EKS runtime accessCLI uses attached role credentials automatically

Use environment variables when needed

Environment variables override file-based configuration in many workflows and are common in CI/CD. Example for a Unix-like shell:

export AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY"
export AWS_DEFAULT_REGION="us-east-1"

aws sts get-caller-identity

# Clear variables after use
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGIONCode language: JavaScript (javascript)

Credential setup workflow

flowchart TD
    A[Install AWS CLI] --> B[Run aws help]
    B --> C[Create or get access key]
    C --> D[Run aws configure]
    D --> E[Credentials and config files saved]
    E --> F[Run sts get caller identity]
    F --> G{Access works}
    G -- yes --> H[Run AWS service commands]
    G -- no --> I[Check profile region and IAM permissions]
    I --> F

Validate and troubleshoot

aws configure list
aws sts get-caller-identity --profile default
aws ec2 describe-instances --region us-west-2 --output tableCode language: PHP (php)

If commands fail, check the active profile, configured region, and IAM permissions for the identity being used.

Common pitfalls and best practices

  • Never commit ~/.aws/credentials or raw keys to Git.
  • Use named profiles instead of constantly overwriting the default profile.
  • Prefer role-based access for compute workloads to avoid long-lived static keys.
  • Use least-privilege IAM policies and rotate keys regularly.
  • Validate identity early with aws sts get-caller-identity before running destructive commands.

References

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Provision an AWS EC2 Instance with Chef (Legacy ChefDK Workflow)

A practical, step-by-step walkthrough for provisioning an AWS EC2 VM using the classic ChefDK and chef-provisioning approach. Includes workflow, commands, recipe examples, and validation checks for legacy environments.

Read More

EC2 Boot from EBS Explained: Architecture, Trade-offs, and an AWS CLI Workflow

Booting Amazon EC2 instances from Amazon EBS was a major shift from ephemeral root disks to persistent root volumes. This guide explains what changed, why it mattered, and how to use the model safely in modern operations.

Read More

Deploying Java EE on Amazon EC2 with EC2Deploy: Workflow, Script, and Modern Lessons

This revised guide breaks down the original EC2Deploy approach for provisioning EC2 instances, deploying Java EE apps, and running JMeter tests. It also maps the same deployment pattern to modern DevOps practices.

Read More

EC2Deploy and the Cloud Tools Maven Plugin: Architecture, Goals, and Deployment Workflow

This revised guide explains what the 2010 EC2Deploy and Cloud Tools release actually introduced, how its components fit together, and how the Maven goals map to deployment operations on EC2. It also covers what modern teams should verify before relying on this legacy toolchain.

Read More

Cloud Tools Adds Amazon EBS Support: Durable EC2 Storage for Database Workloads

This historical update covers when Cloud Tools introduced Amazon EBS support for EC2 applications, including database-backed deployments. It explains the supported storage modes, the backup/restore flow, and practical command-level equivalents.

Read More

EC2 Key Pairs vs AWS Credentials: Practical Fixes for SSH and Security Group Setup

New EC2 users often confuse AWS API credentials with EC2 SSH key pairs, then get blocked by security group rules. This guide separates each concept and shows repeatable CLI and console steps to get instance access working safely.

Read More