在两个不同的aws s3帐户之间复制或传输文档

I want to transfer a file from b1 bucket aws s3 account 1 to b2 bucket aws s3 account 2. Is there a way to doing this using aws php sdk. please help.

You need to have cross account IAM/Policy defined and then have lambda (or) CLI (or) SDK for whatever operations you would like to perform on the resources.

Here is an tutorial provided AWS on how to configure cross account IAM for S3 access.

Firstly, instructions to copy objects in Amazon S3 using PHP can be found here: Copy an Object Using the AWS SDK for PHP

This command also works between buckets -- even buckets in different regions.

Then, to add the requirement of copying objects between accounts:

  • Invoke the copy command with credentials from the receiving account (This helps setup default permissions. If you do it the other way, be sure to set ACL to bucket-owner-full-control.)
  • You need to grant access to the object. So, if you are copying with credentials from the receiving account, you must grant access to the receiving account.

This can best be done in the Bucket Policy on the originating bucket, such as this:

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Sid":"AddPerm",
      "Effect":"Allow",
      "Principal": "arn:aws:iam::RECEIVING-ACCOUNT-ID:user/USERNAME",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::BUCKET-NAME/*"]
    }
  ]
}

Bottom line: Grant access to the objects, then copy the objects!