简体   繁体   English

如何使用Amazon AWS PHP SDK在区域之间复制S3对象?

[英]How to copy S3 objects between regions with Amazon AWS PHP SDK?

I'm trying to copy Amazon AWS S3 objects between two buckets in two different regions with Amazon AWS PHP SDK v3. 我正在尝试使用Amazon AWS PHP SDK v3在两个不同区域的两个存储桶之间复制Amazon AWS S3对象。 This would be a one-time process, so I don't need cross-region replication . 这将是一次性过程,因此我不需要cross-region replication Tried to use copyObject() but there is no way to specify the region. 试图使用copyObject()但没有办法指定区域。

$s3->copyObject(array(
    'Bucket'     => $targetBucket,
    'Key'        => $targetKeyname,
    'CopySource' => "{$sourceBucket}/{$sourceKeyname}",
));

Source: http://docs.aws.amazon.com/AmazonS3/latest/dev/CopyingObjectUsingPHP.html 资料来源: http//docs.aws.amazon.com/AmazonS3/latest/dev/CopyingObjectUsingPHP.html

You don't need to specify regions for that operation. 您无需为该操作指定区域。 It'll find out the target bucket's region and copy it. 它会找出目标桶的区域并复制它。

But you may be right, because on AWS CLI there is source region and target region attributes which do not exist on PHP SDK. 但您可能是对的,因为在AWS CLI上存在PHP SDK上不存在的源区域和目标区域属性。 So you can accomplish the task like this: 所以你可以完成这样的任务:

  1. Create an interim bucket in the source region. 在源区域中创建临时存储桶。
  2. Create the bucket in the target region. 在目标区域中创建存储桶。
  3. Configure replication from the interim bucket to target one. 配置从临时存储桶到目标存储桶的复制。
  4. On interim bucket set expiration rule , so files will be deleted after a short time automatically from the interim bucket. 在临时存储桶设置到期规则中 ,所以文件将在短时间内从临时存储桶中自动删除。
  5. Copy objects from source bucket to interim bucket using PHP SDK. 使用PHP SDK将对象从源存储桶复制到临时存储桶。
  6. All your objects will also be copied to another region. 您的所有对象也将被复制到另一个区域。
  7. You can remove the interim bucket one day later. 您可以在一天后删除临时存储桶。

Or use just cli and use this single command: 或者只使用cli并使用以下单个命令:

aws s3 cp s3://my-source-bucket-in-us-west-2/ s3://my-target-bucket-in-us-east-1/ --recursive --source-region us-west-2 --region us-east-1

Different region bucket could also be different account. 不同的区域桶也可以是不同的帐户。 What others had been doing was to copy off from one bucket and save the data temporary locally, then upload to different bucket with different credentials. 其他人一直在做的是从一个存储桶复制并在本地临时保存数据,然后上传到具有不同凭据的不同存储桶。 (if you have two regional buckets with different credentials). (如果您有两个具有不同凭据的区域存储桶)。

Newest update from CLI tool allows you to copy from bucket to bucket if it's under the same account. CLI工具的最新更新允许您从存储桶复制到存储桶,如果它在同一帐户下。 Using something like what Çağatay Gürtürk mentioned. 使用ÇağatayGürtürk提到的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM