In the fast-paced world of cloud computing, managing and interacting with your resources efficiently is key to success. Amazon Web Services (AWS) provides a powerful tool for this purpose — the AWS Command Line Interface (CLI). The AWS CLI empowers users to interact with AWS services directly from the command line, offering flexibility, speed, and automation capabilities.
Unlock the power of AWS CLI with this step-by-step guide on configuration and command execution. The guide walks you through installation, credential setup, and practical examples for running essential AWS CLI commands.
1
Install AWS CLI
Ensure that you have the AWS CLI installed on your local machine. You can download and install it from the official AWS CLI download page:
https://aws.amazon.com/cli/
2
Open a Terminal or Command Prompt
Open your terminal or command prompt on your local machine.
3
Run aws configure
In the terminal, run:
Run
awsconfigure
4
Enter AWS Access Key ID
When prompted, enter the AWS Access Key ID associated with your IAM user.
5
Enter AWS Secret Access Key
When prompted, enter the AWS Secret Access Key associated with your IAM user.
6
Set Default Region
When prompted, enter the default region you want to use.
7
Set Output Format
When prompted, choose the default output format (for example, json, text, or table).
Example interaction:
Example
AWS Access Key ID [None]: YOUR_ACCESS_KEY_ID
AWS Secret Access Key [None]: YOUR_SECRET_ACCESS_KEY
Default region name [None]: us-central-1
Default output format [None]: json
8
Run AWS CLI Commands
Examples:
List S3 buckets:
List S3 buckets
awss3ls
Describe EC2 instances:
Describe EC2 instances
awsec2describe-instances
Create an S3 bucket:
Create S3 bucket
awss3mbs3://your-new-bucket-name
Upload a file to S3:
Upload file to S3
awss3cplocal-file.txts3://your-new-bucket-name/
Replace placeholder values (bucket name, file path) with your actual values.
9
Verification
You can verify the results of your commands by checking the AWS Management Console or by running additional AWS CLI commands as needed.
Remember to replace placeholder values like YOUR_ACCESS_KEY_ID, YOUR_SECRET_ACCESS_KEY, your-new-bucket-name, and local-file.txt with your actual AWS credentials, bucket names, and file paths.
Multiple AWS CLI profiles
You can store multiple AWS CLI profiles by configuring named profiles in your AWS CLI configuration file (~/.aws/config). This allows you to switch between different AWS accounts or IAM roles easily.
1
Open or create the AWS CLI configuration file
Open your terminal or command prompt and edit the AWS CLI configuration file. If the file doesn’t exist, it will be created:
Edit config
nano~/.aws/config
2
Define AWS CLI profiles
In the configuration file, define multiple profiles using the following syntax: