Introduction
The AWS Command Line Interface (CLI) is a powerful tool for managing AWS services from the command line. This guide covers installation and usage of the AWS CLI, including common commands for managing EC2 instances, S3 buckets, IAM users, DynamoDB tables, and Lambda functions.Installation
-
Download and Install AWS CLI
-
Verify Installation
Basic Configuration
-
Configure AWS CLI
-
List AWS CLI Profiles
-
Get Current AWS CLI Profile
-
Export Default Profile
Storing Multiple Credentials
-
Edit the AWS CLI Configuration File:
The configuration files are located in
~/.aws/credentialsfor credentials and~/.aws/configfor configuration. You can edit these files directly or use theaws configurecommand with the--profileoption.-
Credentials file (
~/.aws/credentials): -
Config file (
~/.aws/config):
-
Credentials file (
-
Add Credentials Using AWS CLI:
You can also use the
aws configurecommand with the--profileoption to add credentials.Follow the prompts to enter theaws_access_key_id,aws_secret_access_key,region, andoutput.
Using Named Profiles
-
Specify a Profile for a Single Command:
You can specify a profile to use for a single AWS CLI command with the
--profileoption. -
Set a Profile as the Default for a Session:
You can set the
AWS_PROFILEenvironment variable to specify which profile to use for the current session.-
Bash:
-
Windows Command Prompt:
-
PowerShell:
-
Bash:
Listing All Profiles
To list all configured profiles, you can use the following command:Example Workflow
-
Configure Profiles:
-
List Profiles:
-
Use a Specific Profile:
-
Set a Profile for a Session:
Now, any subsequent AWS CLI commands will use
profile1credentials until you change the profile or close the session.
By setting up multiple profiles, you can manage and switch between different AWS credentials easily on your local machine.
