Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The specified key does not exist - While copying S3 object from one bucket to another

I am trying to copy a S3 object from one bucket to another and the response is looks like this -

`object(stdClass)#24 (3) { 
          ["error"]=> array(2) { 
              ["code"]=> string(9)
               "NoSuchKey" ["message"]=> string(33)
                "The specified key does not exist." 
       }
          ["code"]=> int(404) ["headers"]=> array(1) {
      ["type"]=> string(15) "application/xml"
    } 
 }

`

Here is how the code looks -

var_dump($this->s3->copyObject('bucket_1','bucket_1/'. images/1.jpg, 'bucket_2', 'bucket_2/images')).die();

According to method signature of copyObject I would need to supply Source object URI and Destination object URI.

Anyone please help me to know what's going wrong here ?

Thanks.

like image 610
user2119554 Avatar asked Oct 18 '14 08:10

user2119554


People also ask

Why can't I copy an object between two Amazon S3 buckets?

To copy an object between buckets, you must make sure that the correct permissions are configured. To copy an object between buckets in the same AWS account, you can set permissions using IAM policies.

Can we move S3 bucket from one account to another?

You can't transfer Amazon S3 bucket ownership between AWS accounts because the bucket is always owned by the account that created it. Instead, you can copy Amazon S3 objects from one bucket to another so that you give ownership of the copied objects to the destination account.


1 Answers

Finally I fixed it after few hours of looking into amazon docs.

Here is what S3 Object keys are -http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-keys

As S3 is a flat file system, the folders are includes in keys,

$this->s3->copyObject('bucket_1','images/1.jpg, 'bucket_2', 'images/copy_of_2.jpg');

ACL can also be passed as a fifth parameters.

like image 51
user2119554 Avatar answered Oct 29 '22 18:10

user2119554