AWS CLI Basic Usage

What AWS CLI that?

Document official website: https://docs.aws.amazon.com/zh_cn/cli/latest/userguide/cli-chap-welcome.html

AWS Command Line Interface (AWS CLI) is an open source tool that allows you to use commands to interact with AWS services from the command line Shell.

Installation AWS CLI

Installation AWS CLI (Python virtual environment-related omitted) in Python virtual environment

$ pip install awscli

View the current version

$ aws --version

Upgrade to the latest version

$ aws install awscli --upgrade

Uninstall

$ pip uninstall awscli

AWS CLI Configuration

Add the default configuration file

Unused AWS CLI, you must first configure the default CLI configuration file

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-2
Default output format [None]: json

Add a Profile for a new role (such as the role of other IAM)

  1. Declare region where the new account in .aws / config file.
[default]
region=ap-northeast-1

[profile ohagi3]
region=ap-northeast-1
  1. Other configuration key role in IAM .aws / credentials file.
[default]
aws_access_key_id=*******
aws_secret_access_key=*******

[ohagi3]
aws_access_key_id=*******
aws_secret_access_key=*******

--Profile default command to specify parameters attached to other IAM roles

$ aws s3 ls --profile ohagi3

Use AWS CLI

Used in conjunction with S3

Bucket list

$ aws s3 ls

List the contents of a bucket of

$ aws s3 ls s3://my-bucket

Upload files to s3 bucket

$ aws s3 cp my-file s3://my-bucket/my-folder

Use in conjunction with DynamoDB

Official documents https://docs.aws.amazon.com/zh_cn/amazondynamodb/latest/developerguide/Tools.CLI.html

View Help

$ aws dynamodb help

Display table list

$ dynamodb list-tables

Inserting data into a table

$ aws dynamodb put-item \
--table-name Music  \
--item \
    '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"}, "AlbumTitle": {"S": "Somewhat Famous"}}' \
--return-consumed-capacity TOTAL  

Issued Query request

key-conditions.json

{
    "Artist": {
        "AttributeValueList": [
            {   
                "S": "No One You Know"
            }   
        ],  
        "ComparisonOperator": "EQ"
    },  
    "SongTitle": {
        "AttributeValueList": [
            {   
                "S": "Call Me Today"
            }   
        ],  
        "ComparisonOperator": "EQ"
    }
}

$ aws dynamodb query --table-name Music --key-conditions file://key-conditions.json

Reproduced in: https: //www.jianshu.com/p/cd7be494435a

Guess you like

Origin blog.csdn.net/weixin_34315665/article/details/91208471