AWS CLI with Access Keys
If you work in cloud computing as an SRE, DevOps Engineer, or Cloud Engineer, you know how often the AWS Command Line Interface (CLI) comes in handy. From automating workflows to simplifying troubleshooting, AWS CLI is a tool that makes your life easier. Let’s walk through how to set it up with access keys step by step.
Why Use AWS CLI?
AWS CLI is your go-to tool for:
- Automation: Say goodbye to repetitive tasks by scripting your workflows.
- Saving Time: Skip the clicks and navigate AWS services directly from your terminal.
- Flexibility: Run complex commands and configurations without needing the Management Console.
What You Need
Before you start, make sure you have:
- An AWS Account with IAM permissions to create access keys.
- AWS CLI Installed on your system. Download it here.
Step 1: Generate Access Keys
Here’s how to create your AWS access keys:
- Log in to the AWS Management Console.
- Go to IAM > Users.
- Select the user you want to create access keys for.
- Open the Security Credentials tab.
- Click Create Access Key.
- Save the Access Key ID and Secret Access Key immediately.
Tip: Store these keys securely! You won’t see the Secret Access Key again after you close this step. Use a password manager or a secure notes app to keep them safe.
Step 2: Set Up AWS CLI
Once you have your access keys, configuring AWS CLI is a breeze:
- Open your terminal.
- Run this command:
aws configure
- Enter the following details when prompted:
- AWS Access Key ID: Paste your Access Key ID.
- AWS Secret Access Key: Paste your Secret Access Key.
- Default Region: For example,
us-west-2
orap-south-1
. - Default Output Format: Choose
json
,table
, ortext
.
Step 3: Verify the Setup
To confirm everything is working, run this command:
aws sts get-caller-identity
This should return details like your IAM user ID, account, and ARN. For example:
{
"UserId": "ABCDEFGHIJKLMNO",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/YourUserName"
}
If something doesn’t look right, double-check your credentials and configuration.
Best Practices for Access Keys
Here are a few tips to keep your keys secure and manageable:
- Rotate Keys Regularly: Don’t let them sit around forever.
- Use IAM Roles: If you’re using EC2, assign an IAM role instead of hardcoding keys.
- Secure Your Keys: Never hardcode them in your scripts. Use AWS Secrets Manager or environment variables instead.
Watch the Video Tutorial
Want to follow along with a hands-on demo? Check out this video.
Leave a Reply