官术网_书友最值得收藏!

Configuring the AWS CLI

Before we can use the AWS CLI, we need to perform a few configuration steps. The fastest way to configure your AWS CLI is with the following command:

$ aws configure
AWS Access Key ID [None]: <your access key>
AWS Secret Access Key [None]: <your secret key>
Default region name [None]: us-east-1
Default output format [None]: json

The explanation of the preceding code is as follows:

  • The first two items that we need to enter are the security credentials so that the CLI has the permissions to perform actions on your behalf. This is the key pair that is contained within the CSV file that we downloaded during the creation of a new user with the IAM service. Open the CSV file and copy and paste the access key ID and the secret access key into the configuration command prompt.
  • Next, for the default region name, we will again use us-east-1 for consistency throughout this book.
  • Finally, for the default output format, enter json. This will set the output for the AWS CLI to be JSON format.

The AWS configure command creates a hidden directory, .aws, in your user home directory, for example, ~/.aws on macOS and Linux. In this directory, two files are created. One is .aws/credentials, with the following code: 

[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_KEY

The other is .aws/config, with the following code:

[default]
region = us-east-1
output = json

Locate these files on your system and verify their contents.

In case you did not copy down or download the access key pair, you can obtain a new key pair in the AWS Management Console:

  1. Navigate to the IAM service under the Security, Identity, & Compliance heading.
  2. In the IAM Management Console, click on Users on the right-hand pane and click on your username.
  3. On the user summary page, click on the Security credentials tab.
  4. Under the Access keys section, click on the Create access key button and a new access key will be created for you.
  5. Remember to delete the old key pair after the new one has been created.

This is how your screen will look:

Remember to configure your AWS CLI with the following command, each time you change your access key:

$ aws configure

Enter your security credentials, default region, and default output format as we explained in the initial AWS CLI configuration.

To test whether the AWS CLI is configured properly, issue the following command:

$ aws s3 ls
2018-12-01 18:01:20 contents.aws.ai
2018-12-01 18:01:49 data.aws.ai
2018-12-01 18:01:35 website.aws.ai

This command will print all of the S3 buckets in your AWS account. More specifically, this command lists the S3 buckets that the user who is associated with the access key has permissions to see. Remember the key pair we configured the CLI with, which belongs to the user to whom we granted the administrative policy? One of the permissions within the administrative policy gives the user access to S3. In any case, you should see the S3 bucket that we created in the previous section of this chapter via the AWS Management Console.

主站蜘蛛池模板: 汨罗市| 万宁市| 临潭县| 封开县| 水富县| 房山区| 乐都县| 富川| 昌乐县| 繁峙县| 桂平市| 湟中县| 房山区| 商丘市| 灵武市| 句容市| 荣昌县| 武强县| 航空| 乾安县| 方山县| 金平| 金川县| 湖北省| 深泽县| 嵩明县| 涟源市| 武平县| 大厂| 禄丰县| 沙洋县| 育儿| 广安市| 北票市| 阳朔县| 新民市| 广元市| 城市| 太康县| 白银市| 新宾|