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:
ACL
to bucket-owner-full-control
.)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!