当前位置: 首页 > 工具软件 > aws-sam-cli > 使用案例 >

「AWS」入门安装aws cli

章乐逸
2023-12-01

cli,即Command Line Interface,是aws服务常用的命令工具

AWS官网地址

  • 环境:Python
  1. 安装

安装起来只需要一条命令:

pip install awscli

执行完成之后,输入aws,输出如下,则说明安装成功了:

$ aws
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: the following arguments are required: command
  • 查看支持的命令,其中的AVAILABLE SERVICES便是支持的命令,内容过多,只罗列了部分
$ aws help
NAME
       aws -

DESCRIPTION
       The  AWS  Command  Line  Interface is a unified tool to manage your AWS
       services.

SYNOPSIS
          aws [options] <command> <subcommand> [parameters]

       Use aws command help for information on a  specific  command.  Use  aws
       help  topics  to view a list of available help topics. The synopsis for
       each command shows its parameters and their usage. Optional  parameters
       are shown in square brackets.
AVAILABLE SERVICES
       o acm

       o acm-pca

       o alexaforbusiness

       o amplify

       o apigateway

       o apigatewaymanagementapi

       o apigatewayv2

       o application-autoscaling

       o appmesh

       o appstream

       o appsync

       o athena

       o autoscaling

       o autoscaling-plans

       o backup

       o batch

       o budgets

       o ce

       o chime

       o cloud9

       o clouddirectory

       o cloudformation

       o cloudfront

       o cloudhsm

       o cloudhsmv2

       o cloudsearch

  1. 配置

其中有一个子命令configure,是用来配置aws cli的。aws cli访问的都是 aws 服务,而每个服务都是需要身份验证的,所以在使用之前,需要先配置身份信息。

同样,先查看configure的说明:

$ aws configure help
NAME
       configure -

DESCRIPTION
       Configure  AWS  CLI  options. If this command is run with no arguments,
       you will be prompted for configuration values such as your  AWS  Access
       Key  Id  and you AWS Secret Access Key.  You can configure a named pro-
       file using the --profile argument.  If your config file does not  exist
       (the default location is ~/.aws/config), the AWS CLI will create it for
       you.  To keep an existing value, hit enter when prompted for the value.
       When  you  are prompted for information, the current value will be dis-
       played in [brackets].  If the config item has no value, it be displayed
       as  [None].  Note that the configure command only work with values from
       the config file.  It does not use any configuration values  from  envi-
       ronment variables or the IAM role.

       Note:  the  values  you  provide  for the AWS Access Key ID and the AWS
       Secret Access Key will  be  written  to  the  shared  credentials  file
       (~/.aws/credentials).

CONFIGURATION VARIABLES
       The following configuration variables are supported in the config file:

       o aws_access_key_id - The AWS access key part of your credentials

       o aws_secret_access_key - The AWS secret access key part of  your  cre-
         dentials

       o aws_session_token  - The session token part of your credentials (ses-
         sion tokens only)

       o metadata_service_timeout - The number of seconds to  wait  until  the
         metadata service request times out.  This is used if you are using an
         IAM role to provide your credentials.

       o metadata_service_num_attempts - The number  of  attempts  to  try  to
         retrieve  credentials.   If you know for certain you will be using an
         IAM role on an Amazon EC2 instance, you can set this value to  ensure
         any intermittent failures are retried.  By default this value is 1.

       For  more information on configuration options, see Configuring the AWS
       Command Line Interface in the AWS CLI User Guide.

       See 'aws help' for descriptions of global parameters.

其中有用的就是CONFIGURATION VARIABLES,一般需要两个参数,aws_access_key_idaws_secrct_access_key,这两个参数登陆AWS后从IAM获取,下面是配置方法,--profile是给当前配置的身份起一个名字,这里起名叫dev

$ aws configure --profile dev
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: 
Default output format [None]: 

执行后会让你输入以上几项,aws_access_key_idaws_secrct_access_key照常填写,后面几项可以不填,也可按需填写。

这样,就配置完成了,使用dev这个身份,就可以访问aws的各种服务了。


到这就算是入门了

 类似资料: