如何下载一个S3 bucket的所有内容,然后上传到另一个bucket?
How to download all the contents of an S3 bucket and then upload to another bucket?
- 我需要将一个 S3 存储桶的内容放入另一个 S3 存储桶中。
- 存储桶在两个不同的帐户中。
- 我被告知不要创建允许从源存储桶访问目标存储桶的策略。
如何使用 AWS CLI 下载原始存储桶的所有内容,然后将内容上传到目标存储桶?
本地复制
aws s3 sync s3://origin /local/path
要复制到目标存储桶:
aws s3 sync /local/path s3://destination
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 每个命令使用哪组凭据。
- 我需要将一个 S3 存储桶的内容放入另一个 S3 存储桶中。
- 存储桶在两个不同的帐户中。
- 我被告知不要创建允许从源存储桶访问目标存储桶的策略。
如何使用 AWS CLI 下载原始存储桶的所有内容,然后将内容上传到目标存储桶?
本地复制
aws s3 sync s3://origin /local/path
要复制到目标存储桶:
aws s3 sync /local/path s3://destination
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 每个命令使用哪组凭据。