Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

S3: Make uploaded files public by default

I have a public S3 Bucket, with the public policy set like this

{
    "Version": "2012-10-17",
    "Id": "Policy1563368389080",
    "Statement": [
        {
            "Sid": "Stmt1563368385984",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion"
            ],
            "Resource": [
                "arn:aws:s3:::mybucketname/*",
                "arn:aws:s3:::mybucketname"
            ]
        }
    ]
}

However when i upload a new file it isn't public by default. Is there something wrong with my policy?

like image 875
Jimi Avatar asked Oct 08 '19 08:10

Jimi


People also ask

What is the default setting for S3 storage visibility?

By default, all Amazon S3 buckets and objects are private. Only the resource owner which is the AWS account that created the bucket can access that bucket. The resource owner can, however, choose to grant access permissions to other resources and users.

Are S3 objects public by default?

By default, new S3 bucket settings do not allow public access, but customers can modify these settings to grant public access using policies or object-level permissions.

Is S3 public or private by default?

By default, all S3 buckets are private and can be accessed only by users who are explicitly granted access. Restrict access to your S3 buckets or objects by doing the following: Writing IAM user policies that specify the users that can access specific buckets and objects.


1 Answers

To make it public by default you need to add below code under bucket policy of you respective aws S3 bucket.

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

enter image description here

like image 181
Nabeel Shaikh Avatar answered Oct 18 '22 05:10

Nabeel Shaikh