[AWS] AWS

摘要:
AWSCommandLineInterface(AWSCLI)是一个命令行工具,允许使用终端/命令提示符中的命令与AWS服务进行交互

The AWS Command Line Interface (AWS CLI) is a command-line tool that allows you to interact with AWS services using commands in your terminal/command prompt.

AWS CLI enables you to run commands to provision, configure, list, delete resources in the AWS cloud. Before you run any of the aws commands, you need to follow three steps:

  1. Install AWS CLI
  2. Create an IAM user with Administrator permissions
  3. Configure the AWS CLI

Step 1. Install AWS CLI v2

Refer to the official AWS instructions to install/update AWS CLI (version 2) based on your underlying OS. You can verify the installation using the following command in your terminal (macOS)/cmd (Windows).

# Display the folder that contains the symlink to the aws cli tool
which aws
# See the current version
aws --version

See the sample output below. Note that the exact version of AWS CLI and Python may vary in your system.

[AWS] AWS第1张

Mac/Linux/Windows: Verify the successful installation of AWS CLI 2

Step 2. Create an IAM user

In this step, you will create an IAM user with Administrator permissions who is allowed to perform any action in your AWS account, only through CLI. After creating such an IAM user, we will use its Access key (long-term credentials) to configure the AWS CLI locally.

Let’s create an AWS IAM user, and copy its Access key.

AWS Identity and Access Management (IAM) service allows you to authorize users / applications (such as AWS CLI) to access AWS resources.

The Access key is a combination of an Access Key ID and a Secret Access Key. Let's see the steps to create an IAM user, and generate its Access key.

[AWS] AWS第2张

Add a new IAM user

  • Set the user details, such as the name, and access type as Programmatic access only.
[AWS] AWS第3张

Set the user name, and type (mode) of access

  • Set the permissions to the new user by attaching the AWS Managed AdministratorAccess policy from the list of existing policies.
[AWS] AWS第4张

Attach the AdministratorAccess policy from the list of pre-created policies

  • Provide tags [optional], review the details of the new user, and finally create the new user.
  • After a user is created successfully, download the access key file (.csv) containing the Access Key ID and a Secret Access Key. You can even copy the keys and stay on the same page. Don’t skip this step as this will be your only opportunity to download the secret access key file.
[AWS] AWS第5张

Copy the Access key of the new user OR download the .csv file containing the Access key

Step 3. Configure the AWS CLI

You will need to configure the following four items on your local machine before you can interact with any of the AWS services:

  1. Access key - It is a combination of an Access Key ID and a Secret Access Key. Together, they are referred to as Access key. You can generate an Access key from the AWS IAM service, and specify the level of permissions (authorization) with the help of IAM Roles.
  2. Default AWS Region - It specifies the AWS Region where you want to send your requests by default.
  3. Default output format - It specifies how the results are formatted. It can either be a json, yaml, text, or a table.
  4. Profile - A collection of settings is called a profile. The default profile name is default, however, you can create a new profile using the aws configure --profile new_name command. A sample command is given below.

If you have closed the web console that showed the access key, you can open the downloaded access key file (.csv) to copy the keys later. It should be something similar to:

AWSAccessKeyId=WANI9WATIG63GKCXA89VC74A
AWSSecretKey=kMT2Jn5NPkq1GxtoUqwUbgHtPbsf1ODm/Pbsf1OD
[AWS] AWS第6张

Mac/Linux: List your present configuration, and then configure your default aws profile

  • Navigate to the home directory and check the current configuration:
    # Navigate to the home directory
    cd
    # View the current configuration
    aws configure list
    
  • Set the default profile credentials
    aws configure --profile default
    
    The command above will store the access key in a default file ~/.aws/credentials and store the profile in the ~/.aws/config file. Upon prompt, paste the copied access key (access key id and secret access key). Enter the default region as us-east-1 and output format as json.
  • Let the system know that your sensitive information is residing in the .aws folder
    export AWS_CONFIG_FILE=~/.aws/config
    export AWS_SHARED_CREDENTIALS_FILE=~/.aws/credentials
    
[AWS] AWS第7张

Mac/Linux: A successful configuration

  • After a successful credential set-up, your "credentials" file will look like:
[AWS] AWS第8张

Mac/Linux: View the credentials file using cat ~/.aws/credentials command

  • Windows users with GitBash only
    You will have to set the environment variables. Run the following commands in your GitBash terminal:
    setx AWS_ACCESS_KEY_ID AKIAIOSFODNN7EXAMPLE
    setx AWS_SECRET_ACCESS_KEY wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    setx AWS_DEFAULT_REGION us-west-2
    
    Replace the access key ID and secret, as applicable to you. Windows users using WSL do not need this step, they will follow all steps as if they are Linux users.
[AWS] AWS第9张

Windows: Successful configuration using the GitBash terminal

Step 4. Run your first AWS CLI command

  • Check the successful configuration of the AWS CLI, by running an AWS command:
    aws iam list-users
    
    The output will display the details of the recently created user:
    {
    "Users": [
        {
            "Path": "/",
            "UserName": "Admin",
            "UserId": "AIDAZMXYZ3LY2BNC5ZM5E",
            "Arn": "arn:aws:iam::388752792305:user/Admin",
            "CreateDate": "2021-01-28T13:44:15+00:00"
        }
    ]
    }
    

Troubleshoot

If you are facing issues while following the commands above, refer to the detailed instructions here -

  1. Configuration basics
  2. Configuration and credential file settings
  3. Environment variables to configure the AWS CLI

Updating the specific variable in the configuration

In the future, you can set a single value, by using the command, such as:

# Syntax
# aws configure set <varname> <value> [--profile profile-name]
 aws configure set default.region us-east-2

It will update only the region variable in the existing default profile.

免责声明:文章转载自《[AWS] AWS》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Loadrunner 11安装和破解cocos2d-x 模态对话框的实现下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

iris 框架在服务端解决跨域问题

1. 编写中间件,将允许跨域的header添加到响应头 //Cors funcCors(ctxiris.Context){ ctx.Header("Access-Control-Allow-Origin","*") //ctx.Header("Access-Control-Allow-Headers","DNT,X-Mx-ReqToken,Keep-Al...

[OAuth]基于DotNetOpenAuth实现Client Credentials Grant

Client Credentials Grant是指直接由Client向Authorization Server请求access token,无需用户(Resource Owner)的授权。比如我们提供OpenAPI让大家可以获取园子首页最新随笔,只需验证一下Client是否有权限调用该API,不需要用户的授权。而如果Client需要进行发布博客的操作,就...

亚马逊AWS学习——多网络接口下配置EC2实例连接公网的一个“bug”

转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/47667627本文出自【我是干勾鱼的博客】 之前在《亚马逊AWS学习——EC2的自己定义VPC配置》这篇文章中讲述了怎样设置自己定义VPC并使自己的EC2实例能够连接公网。本篇说一下连接公网时会出现的一个小问题。 如题所看到的,在一个EC...

首次使用AWS服务器EC2

AWS有一年的免费套餐,这个便宜我得占。 申请的时候需要填写银行卡,AWS暂不支持储蓄卡,只好绑信用卡了。 创建EC2实例之后,下一个要解决的问题就是远程root访问。 1. 修改安全组设置 2. su passwd设置root密码 3. 修改/etc/ssh/sshd_config PasswordAuthentication yes PermitRo...

CORS(跨域资源共享)

引用自阮一峰的网络日志:http://www.ruanyifeng.com/blog/2016/04/cors.html 侵删 一、浏览器将CORS请求(通过ajax方式)分成两类: 1.简单请求:需要同时满足以下两大条件 1).请求方法为:HEAD、GET、POST之一 2).HTTP的请求头信息不超出以下字段:Accept、Accept-Languag...

一个简单的判断文件是否存在的WIN API函数

int _access( const char *path, int mode ); int _waccess( const wchar_t *path, int mode ); 可以判断文件是否path存在。 mode                Checks file for 00                    Existence onl...