设置用于示例演练的工具 - Amazon Simple Storage Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

设置用于示例演练的工具

介绍性示例(请参阅 示例演练:管理对 Amazon S3 资源的访问)使用 Amazon Web Services Management Console 来创建资源和授予权限。为了测试权限,这些示例使用命令行工具 Amazon Command Line Interface (CLI) 和 Amazon Tools for Windows PowerShell,因此您无需编写任何代码。要测试权限,您必须设置其中的一个工具。

设置 Amazon CLI
  1. 下载并配置 Amazon CLI。有关说明,请参阅Amazon Command Line Interface 用户指南中的以下主题。

    开始设置 Amazon Command Line Interface

    安装 Amazon Command Line Interface

    配置 Amazon Command Line Interface

  2. 设置默认的配置文件。

    您将用户凭证存储在 Amazon CLI 配置文件中。使用 Amazon Web Services 账户凭证在配置文件中创建默认配置。有关查找和编辑 Amazon CLI 配置文件的说明,请参阅配置和凭证文件

    [default] aws_access_key_id = access key ID aws_secret_access_key = secret access key region = us-west-2
  3. 在命令提示符处输入以下命令来验证设置。这两个命令没有显式提供凭证,因此将使用默认配置的凭证。

    • 尝试 help 命令

      aws help
    • 使用 aws s3 ls 获取所配置账户的存储桶列表。

      aws s3 ls

当您进行示例演练时,您将创建用户,并且通过创建配置将用户凭证保存在配置文件中,如以下示例所示。请注意,这些配置都有名称 (AccountAadmin 和 AccountBadmin) :

[profile AccountAadmin] aws_access_key_id = User AccountAadmin access key ID aws_secret_access_key = User AccountAadmin secret access key region = us-west-2 [profile AccountBadmin] aws_access_key_id = Account B access key ID aws_secret_access_key = Account B secret access key region = us-east-1

要使用这些用户凭证来运行命令,请添加 --profile 参数来指定配置文件名称。以下 Amazon CLI 命令检索 examplebucket 中对象的列表,并指定 AccountBadmin 配置文件。

aws s3 ls s3://examplebucket --profile AccountBadmin

或者,您也可以从命令提示符处更改 AWS_DEFAULT_PROFILE 环境变量,将一组用户凭证配置为默认的配置文件。完成此操作后,当执行不带 --profile 参数的 Amazon CLI 命令时,Amazon CLI 会将您在环境变量中设置的配置文件用作默认配置文件。

$ export AWS_DEFAULT_PROFILE=AccountAadmin
要设置 Amazon Tools for Windows PowerShell,请按以下步骤操作:
  1. 下载并配置 Amazon Tools for Windows PowerShell。有关说明,请转到 Amazon Tools for Windows PowerShell 用户指南中的下载和安装 Amazon Tools for Windows PowerShell

    注意

    为了加载 Amazon Tools for Windows PowerShell 模块,您需要启用 PowerShell 脚本执行。有关更多信息,请参阅 Amazon Tools for Windows PowerShell 用户指南中的启用脚本执行

  2. 对于这些练习,您需使用 Set-AWSCredentials 命令指定每个会话的 Amazon 凭证。该命令会将凭证保存到持久存储 (-StoreAs 参数)。

    Set-AWSCredentials -AccessKey AccessKeyID -SecretKey SecretAccessKey -storeas string
  3. 验证设置。

    • 运行 Get-Command 以检索可用于 Amazon S3 操作的命令的列表。

      Get-Command -module awspowershell -noun s3* -StoredCredentials string
    • 运行 Get-S3Object 命令以检索存储桶中的对象的列表。

      Get-S3Object -BucketName bucketname -StoredCredentials string

有关命令的列表,请参阅 Amazon Simple Storage Service Cmdlet

您现在可以着手开始练习。访问本部分开头提供的链接。