AWS CLI
CLI Configuration
Quick configuration
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
To update any of your settings, simply run aws configure
again and enter new values as appropriate.
# can specify a particular profile name:
$ aws configure --profile profilename
The AWS CLI looks for credentials and configuration settings in the following order:
- Command Line Options – region, output format and profile can be specified as command options to override default settings.
- Environment Variables – AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, etc.
- The AWS credentials file – located at ~/.aws/credentials. This file can contain multiple named profiles in addition to a default profile.
- The CLI configuration file – typically located at ~/.aws/config. This file can contain a default profile, named profiles, and CLI specific configuration parameters for each.
- Instance profile credentials – these credentials can be used on EC2 instances with an assigned instance role, and are delivered through the Amazon EC2 metadata service.
Configure by using credential and config files
#~/.aws/credentials
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
[user2]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY
#~/.aws/config
[default]
region=us-west-2
output=json
[profile user2]
region=us-east-1
output=text
- Used named profile with CLI:
$ aws ec2 describe-instances --profile user2
- you can avoid specifying the profile in every command by setting the AWS_DEFAULT_PROFILE environment variable at the command line:
$ export AWS_DEFAULT_PROFILE=user2
-
Command line option
The following settings can be specified at the command line.
--profile – name of a profile to use, or "default" to use the default profile.
--region – AWS region to call.
--output – output format.
--endpoint-url -
test CLI configuration with list EC2 instance:
aws ec2 describe-instances --profile jinchao-full-access --output table --region us-west-2
CLI basic command
General
aws configure
aws configure --profile profile-name
S3:
aws s3 ls
EC2
aws ec2 describe-instances --instance-ids <instance-id>
aws ec2 start-instances --instance-ids <instance-id>
aws ec2 stop-instances --instance-ids <instance-id>
aws ec2 reboot-instances --instance-ids <instance-id>
aws ec2 terminate-instances --instance-ids <instance-id>
aws ec2 get-console-output --instance-id <instance-id>
aws ec2 describe-security-groups --group-names <group-name>
IAM
VPC
aws ec2 describe-vpcs
aws ec2 describe-subnets --filters Name=vpc-id,Values=<vpc-id>
aws ec2 describe-route-tables --filters Name=vpc-id,Values=<vpc-id>
aws ec2 describe-network-acls --filters Name=vpc-id,Values=<vpc-id>
aws ec2 describe-vpc-peering-connections