简体   繁体   中英

Access denied error on aws s3 when uploading a file from an ec2 instance that is on a different account

I have this instance I recently launched. I want to upload an Image file to s3. But whenever I try to access the uploaded file, I get the error:

AccessDenied Access Denied

Everytime a file is uploaded, I am saving the file url in database. I then paste that url in the browser. Then it gives me the error. When uploaded from local server, that url simply downloads the file (in this case an Image).

Here is the policy permissions

{ "Version": "2012-10-17", "Statement": [ { "Sid": "PublicRead", "Effect": "Allow", "Principal": "*", "Action": [ "s3:GetObject", "s3:GetObjectVersion" ], "Resource": "arn:aws:s3:::<bucketname>/*" } ]

}

When I upload a file from local server, it works fine. When I upload a file from the instance that belongs to same user as s3 bucket. It works fine. This particular instance isn't created using the same account as s3 bucket. I don't know if that is a problem or not.

You mentioned that you are accessing the file via a URL in a web browser. This should work fine with the Bucket Policy you have shown in your question, since it is making the bucket public.

If you are uploading the file from credentials that belong to a different AWS Account, then you should use ACL=public-read when doing the upload. This will grant ownership of the object to the account that owns the bucket.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM