Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving read permission to object uploaded via PutObjectRequest in amazon s3

I am uploading text file to Amazon s3 bucket via java application. I want to set read access fot that file for everyone. Does anyone know how to do this ? or direct me to some appropriate resources ?

like image 691
slonkar Avatar asked Nov 09 '12 00:11

slonkar


People also ask

Why can't I access an object that was uploaded to my Amazon S3 bucket by another AWS account?

For these existing buckets, an object owner had to explicitly grant permissions to an object (by attaching an access control list). Otherwise, the bucket owner would be unable to access the object.


1 Answers

You can create a bucket policy that make all resources (or those who match a wildcard) available.

Click on your bucket properties on aws S3 console and edit the bucket policy to something like :

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

Where bucket in the Resource parameter is your bucket name.

Also you can set public permission for a specific file via Java API :

PutObjectRequest por = new PutObjectRequest(bucketName, key, file);
por.setCannedAcl(CannedAccessControlList.PublicRead);
s3.putObject(por);
like image 65
lstern Avatar answered Oct 04 '22 02:10

lstern