How to Configure AWS CLI on Linux
The AWS Command Line Interface (CLI) is a powerful tool that lets you interact with AWS services using commands in your terminal. This guide walks you through the process of installing and configuring the AWS CLI on a Linux system.
Why Use AWS CLI?
AWS CLI offers:
- A quick and efficient way to interact with AWS services.
- Automation capabilities for AWS resource management.
- Flexibility to script complex operations.
Step 1: Install AWS CLI
To install AWS CLI on your Linux system, follow these steps:
- Download the installation script:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
-
Ensure unzip is installed:
- For Ubuntu/Debian:
sudo apt update && sudo apt install unzip -y
-
For Fedora/RHEL:
sudo dnf install unzip -y
- Extract the ZIP file:
unzip awscliv2.zip
- Run the installer:
sudo ./aws/install
- Verify the installation:
aws --version
The output should display the installed version of AWS CLI.
- Clean up temporary files:
rm awscliv2.zip
rm -r aws/
Step 2: Configure AWS CLI
After installation, configure AWS CLI with your credentials and default settings.
- Run the configure command:
aws configure
-
Provide the required information:
- AWS Access Key ID (e.g.,
AKIAIOSFODNN7EXAMPLE
) - AWS Secret Access Key (e.g.,
wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY
) - Default region (e.g.,
ap-southeast-2
) - Output format (e.g.,
json
)
- AWS Access Key ID (e.g.,
Test the configuration:
aws s3 ls
This command lists all your S3 buckets, confirming that AWS CLI is configured correctly.
Step 3: Advanced Configuration
Setting Multiple Profiles
You can configure multiple AWS profiles for different accounts or environments.
- Create a new profile:
aws configure --profile <profile-name>
- Use a profile:
aws s3 ls --profile <profile-name>
Using Environment Variables
Environment variables can override default configuration settings.
- Set environment variables:
export AWS_ACCESS_KEY_ID=<your-access-key-id>
export AWS_SECRET_ACCESS_KEY=<your-secret-access-key>
export AWS_DEFAULT_REGION=ap-southeast-2
- Test the configuration:
aws ec2 describe-instances
Step 4: Automate AWS CLI Commands
Create shell scripts to automate AWS operations. For example:
#!/bin/bash
# Script to list S3 buckets
aws s3 ls
Make the script executable:
chmod +x list_buckets.sh
Run the script:
./list_buckets.sh
Conclusion
The AWS CLI is an essential tool for any AWS user. By following this guide, you can quickly set up and start using AWS CLI to manage your cloud resources effectively. Happy coding! 🚀
Top comments (0)