How to configure aws s3 bucket to accept signed Heroku urls?

I am using Node.js to get the signed url from aws s3 using putObject from the module (aws-sdk). When I start my server locally, there is no problem loading on S3. When I deploy my code to heroku and select the file to upload, I get the following error on my Chrome console:

https://torhuw-hrns.s3.amazonaws.com/5f522890-0283-11e6-a696-b1fc6f56c785-T ... 4 & Signature = P7ybw4% 2B2qqNRNKTZbc% 2FMWLhPn1o% 3D & x-amz-acl = public-read- write Failed to load resource: server responded with status 403 (Forbidden)

I am using the Node.js (aws-sdk) s3getSignedUrl method to get the signature and send it to the front to load my files into my s3 bucket.

Next Tutorial - Direct Download of S3 Files to Node.js

+5
source share
2 answers

Double-check your rights to the S3 bucket and CORS configuration. You need to make sure that the policy allows "s3: PutObject" in your bucket, and you need to make sure that CORSRule allows PUT / POST and allows your application domain.

To debug these things, you might consider temporarily loosening all of your โ€œwide openโ€ permissions and checking that it works when it is completely unlimited.

+1
source

Ok, I solved this by creating a new bucket updating the CORS configuration, creating a new access_key_ID and access_secret_access_key and updating the heroku environment variables (I also selected the bucket to be in the same region as my heroku application, but not sure, however, this is was a decision). The CORS configuration was used:

<?xml version="1.0" encoding="UTF-8"?> <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <CORSRule> <AllowedOrigin>*</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>PUT</AllowedMethod> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration> 
0
source

Source: https://habr.com/ru/post/1247155/


All Articles