Installing AWS CLI and Configuring Environment Variables
AWS CLI (Command Line Interface) is a powerful tool that lets you interact with AWS services directly from your terminal. To get started with AWS CLI, you’ll need to install the software, configure it's path, and manage authentication effectively.
Add AWS CLI to System Path:
On Windows: The installer usually handles this automatically. If not, you can manually add the path (e.g.,
C:\Program Files\Amazon\AWSCLI\bin
) to your system environment variables.On macOS/Linux: The installation script should handle this. If not, you can add the path to your shell configuration file (e.g.,
.bashrc
,.zshrc
) with the following line:export PATH=$PATH:/usr/local/bin/aws
Using .pem Files for Authentication to instances
AWS uses key pairs (.pem files) to securely connect to your instances. These files contain the private key and are essential for accessing resources via CLI. Here’s how you can manage them:
ssh -i /path/to/your-key.pem ec2-user@your-instance-public-dns
Checking AWS CLI Connectivity
Step 1: Verify AWS CLI Configuration
aws configure list
This command displays the current configuration settings, such as AWS access key, secret key, and region.
Step 2: Verify AWS IAM Identity
aws sts get-caller-identity
This command returns details about the IAM user or role making the request, which helps verify that your CLI is properly connected.
Removing AWS CLI Credentials and Configuration
Step 1: Remove AWS CLI Credentials and Configuration Files
Execute the following commands to delete the credentials and configuration files:
rm -rf ~/.aws/credentials
rm -rf ~/.aws/config
Step 2: Unset Environment Variables
If you’ve set environment variables for AWS credentials, unset them to ensure they are no longer used:
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
unset AWS_SESSION_TOKEN
unset AWS_DEFAULT_REGION