Amazon S3 copyObject permission

前端 未结 3 1959
梦毁少年i
梦毁少年i 2020-12-29 03:56

I\'v got user with all permissions.

{
  \"Statement\": [
    {
      \"Effect\": \"Allow\",
      \"Action\": \"*\",
      \"Resource\": \"*\"
    }
  ]
}
         


        
3条回答
  •  攒了一身酷
    2020-12-29 04:29

    I know this is an old question, but I ran into the same issue recently while doing work on a legacy project.

    $this->client->copyObject([
        'Bucket'        => $this->bucket,
        'CopySource'    => $file,
        'Key'           => str_replace($source, $destination, $file),
    ]);
    

    All of the my other S3 calls worked except for copyObject continued to throw an ACCESS DENIED error. After some digging, I finally figured out why.

    I was passing just the key and making the assumption that the bucket being passed was what both the source and destination would use. Turns out that is an incorrect assumption. The source must have the bucket name prefixed.

    Here was my solution:

    $this->client->copyObject([
        'Bucket'        => $this->bucket,
        // Added the bucket name to the copy source
        'CopySource'    => $this->bucket.'/'.$file,
        'Key'           => str_replace($source, $destination, $file),
    ]);
    

    It says "Access Denied" because it thinks the first part of your key/folder is actually the name of the bucket which either doesn't exist or you really don't have access to.

    Hope that helps a few people out!

提交回复
热议问题