【问题标题】:How to download all the contents of an S3 bucket and then upload to another bucket?如何下载一个 S3 存储桶的所有内容,然后上传到另一个存储桶?
【发布时间】:2016-05-03 08:48:52
【问题描述】:
  • 我需要将一个 S3 存储桶的内容放入另一个 S3 存储桶。
  • 存储桶位于两个不同的帐户中。
  • 有人告诉我不要创建允许从源存储桶访问目标存储桶的策略。

如何使用 AWS CLI 下载源存储桶的所有内容,然后将内容上传到目标存储桶?

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-cli


    【解决方案1】:

    本地复制

    aws s3 sync s3://origin /local/path
    

    复制到目标存储桶:

    aws s3 sync /local/path s3://destination 
    

    【讨论】:

      【解决方案2】:

      aws cli 允许您配置命名配置文件,让您可以为每个单独的 cli 命令使用一组不同的凭据。这会很有帮助,因为您的存储桶位于不同的帐户中。

      要创建您的命名配置文件,您需要确保您的每个账户中都已拥有 IAM 用户,并且每个用户都需要一组访问密钥。像这样创建两个命名配置文件。

      aws configure --profile profile1
      aws configure --profile profile2
      

      这些命令中的每一个都会要求您提供访问密钥和要使用的默认区域。一旦你有了两个配置文件,就可以像这样使用 aws cli。

      aws s3 cp s3://origin /local/path --recursive --profile profile1
      aws s3 cp /local/path s3://destination --recursive --profile profile2
      

      请注意,您可以使用 --profile 参数告诉 cli 为每个命令使用哪一组凭据。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-29
        • 1970-01-01
        • 2022-06-12
        • 2018-06-02
        • 2020-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多