Ruby S3 "Access Denied" error while calling upload_file with ACL

I am trying to write a Ruby script that uploads a file to AWS and makes the file public. I have done the following:

s3 = Aws::S3::Resource.new(
    credentials: Aws::Credentials.new(KEY, SECRET),
    region:'us-west-2'
)
obj = s3.bucket('stg-db').object('key')
obj.upload_file(filename)

This seems to work fine except that the file is not accessible and I cannot get a public URL for it. But when I enter S3, I see that my file is just fine.

To make it public, I changed the last line to

obj.upload_file(filename, acl: 'public-read')

But I get an access denied error when I do this. Is there some kind of permission setting that I skip in my S3 bucket that causes problems, or am I calling it that wrong?

+4
source share
1 answer

, S3, , .

AWS:

, , Object ACL Object Delete . JSON:

{
"Version": "2012-10-17",
"Id": "Policy1441134540846",
"Statement": [
    {
        "Sid": "Stmt1441134537688",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::MY_USER_ID:user/myemail@example.com"
        },
        "Action": [
            "s3:DeleteObject",
            "s3:PutObjectAcl",
            "s3:PutObject"
        ],
        "Resource": "arn:aws:s3:::MY_BUCKET/*"
    }
]
}

:

  • 3 "" JSON. IAM .
  • . , , , ( "/*" MY_BUCKET) . (- " - () ...", , , .
  • , , ( "*" ), . , , .
+6

All Articles