Introduction:
An Amazon S3 bucket is a public cloud storage resource available in Amazon Web Services’ (AWS). S3 stands for Simple Storage Service (S3) and it is an object storage offering. Amazon S3 buckets, which are similar to file folders, store objects which consist of data and its descriptive metadata.
Amazon S3 provides a web service which can be used to store and retrieve unlimited amounts of data. The same can be done programmatically using Amazon-provided APIs.S3 in Amazon has two primary entities called buckets and objects. Objects are stored inside buckets.
By default, the maximum number of buckets that can be created per account is 100. For additional buckets, one can submit a request for a service limit increase. Bucket names have to be globally unique irrespective of which region they are created in. As buckets can be accessed using URLs, it is recommended that bucket names follow DNS naming conventions: all letters should be in lowercase.
Approach:
If you are using a bucket in your project you must follow this
Decide the Bucket Structure:
First, decide the structure of the bucket you are creating. For example, if your bucket is going to store images, pdf files of different images and doc. then it should be arranged properly. Let’s say you have Interviewer Resume and Candidate Resume then the ideal structure will be.
Data
Interviewer (id-32)
– Resume
32_Int_Res.pdf
– Profile Pic
32_Int_Pic.jpg
Candidate (id-12)
– Resume
12_Can_Res.pdf
– Profile Pic
12_Can_Pro.jpg
Once you can finalise the structure of your folder then it should be followed in the bucket you are creating.
1. Creating and Naming Bucket:
After deciding the structure, Using required naming conventions(all letter should be in lowercase) create two buckets for
- Production
- QA and Staging
2. Naming Convention:
The naming convention must be unique for every file and folder and it is related to the file you are creating for example by seeing the name you can identify what is in it.
3. Linking Bucket with Database:
Now when you have created the bucket with the required folder structure, you have to link it with the database.
For this you have to do these following steps:
Saving in the Bucket :
When you are saving anything in the S3 Bucket you will do it by creating a POST API, here in this API you will define the path in the bucket where you want to save your file. Once the path is defined the file will get saved in the defined folder in the bucket. The path of the particular file in the bucket will save in the DB according to the required id.
Getting a file from the bucket :
When you want to access the file from the bucket, you do it by creating a GET API, this API basically picks the path for the required file in the bucket from DB, GET API creates an assigned URL using the path and sends it in desired response and you will get the required data.