Assign permission in an entire directory inside Amazon S3 Bucket (PHP)

194

I'm using AWS SDK + PHP + Symfony2.

Is there a way to assign public-read permission to an entire directory that I've just uploaded to an Amazon S3 Bucket?

The code I normally use to assign a public-read permission is:

$this->s3->putObjectAcl(
    array(
        'Bucket' => $this->bucketName,
        'Key' => $destinationPath,
        'ACL' => CannedAcl::PUBLIC_READ
    )
);

But it doesn't work if $destinationPath is a directory. Is there a way to achieve that?

594

Answer

Solution:

As urfusion mentioned, what you're looking for is a Bucket Policy.

Here's an example policy you might use :

{
  "Version":"2012-10-17",
  "Statement":[
    {
      "Sid":"PublicReadGetObject",
      "Effect":"Allow",
      "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3

People are also looking for solutions to the problem: php - Trying to access url that returns json results in connection reset by peer error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.