How to configure AWS S3 bucket policies so that uploaded files are readable as public files.
Could somebody please give an example for node js code?
I am a novice to the field so I do not have prior experience regarding this. Any help is highly appreciated.
3
Answers
You can check out this official documentation of AWS s3 for NodeJS that explains how to update bucket policies
There are several steps in this process.This instructions are applicable for nodejs 14 (runtime: nodejs14.x)
First you have to follow the below link format after logging in to your AWS account
You should follow the below format.
https://s3.console.aws.amazon.com/s3/buckets/{BUCKET-NAME}?region={REGION}&tab=permissions#
This is an example link
https://s3.console.aws.amazon.com/s3/buckets/logo?region=us-east-1&tab=permissions#
image: This is an example of entering the path
Second step is creating bucket policies. Replace the word "BUCKET-NAME" with the name of your bucket.
}
image: Bucket policies JSON configuration
Then create an endpoint on serverless.yml following the below code. file_upload function is included in handler.js file.
serverless.yml
After that you have to program handler.js file as below
handler.js
A link for AWS documentation is attached below
https://docs.aws.amazon.com/AmazonS3/latest/userguide/example-bucket-policies.html
The easiest way to make every object in a bucket publicly accessible is to add this Bucket Policy to the bucket:
This will make every bucket publicly accessible, if they know the filename (Key) of the object.
To add this Bucket Policy, you will need to turn off S3 Block Public Access (the two options that mention ‘Bucket Policy’).