How To Setup An AWS S3 Bucket And Configure In Node.js - Part 1
Tags: node, aws, javascript
Published: 2023-04-09 19:05:15

So, for developers new to AWS, especially the S3 Bucket, the S3 Bucket is a simple storage service in the cloud that houses images, videos, and other documents. It also provides a secure and scalable for users or developers to manage their data.
Now, in order to interact with your S3 to perform various operations like uploading a file to deleting it, we use the AWS SDK.

So let head right in!!!!
Firstly, you would have to create an account, if you don't have an account you can follow this link [here](https://aws.amazon.com/).
And this should be the page you should see as in 2023.

![Sign in page for AWS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/56h304w1e0wk27ik7nhe.PNG)

Once we sign-in or sign-up, this is where we will be taken to,

![aws home console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ofbbtbeao39vsy0lybh8.PNG)
and if you don't see anything in **`Recently visited`**, don't worry.
So we will first create our policy, and user, then create our S3 bucket.
See the search bar on the navbar? click on it and type **`aim`** 

![click on iam](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/897dqu83zb8v06s5a5xk.PNG)and click and on it. Then you will be taken to the IAM Dashboard. 

On the sidebar, look for **`Policies`**, and keep note we also have **`Users`** there, and that's where we will go next after creating the policy. And also don't worry if your dashboard doesn't look like mine.
![select policies](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4250qddd86v80u984r4q.PNG)

Once we are at the policies page, we create our own custom policy, the reason is that, we want to upload files, delete files, and update files, which gives us the read and write access permission to our user or developer to manage the S3 bucket in Node.js application, otherwise we'll definitely run into a problem with our application.

Let's continue...
Click on **`create policy`**
![creating aws policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgmr4j7a27r4dkvidofj.PNG)

Then we click on Choose a service.
Then we type **`S3`** in the search bar, and with the options that show, we select S3.
![select s3 bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i75e5osj1kbingwtvi10.PNG)

There, the next step is to select the permission we want to assign to our S3 bucket. So, we check the radio for **`Read`**, to retrieve data from the s3 bucket and read it (Meaning making a  GET request).
![choose getobject](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bh4dxh2dlva5479fkdjt.PNG)

Now with all the option selected, we only need to check one, which is the **`GetObject`**, then with the **`write`** radio selected, we check two items which are **`DeleteObject`**, and **`PutObject`**
![Select writeObject](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f60m0tqwsps8d6y2tmtc.PNG)

So the next step is the **`Resources`**, after you click on it, it expands then click on **`Add ARN`**, a screen pop-ups, there we have two fields to fill, one is the **`Bucket name`**, and the other is the **`Object name`**.  Since we haven't create our bucket, we type the name we would give to the S3 bucket when creating it, in this case mine is **`nodebucket`**, and the Object name we put `*`.
![done](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oin8bzimpdg3wume5jfd.PNG)

After, click on **`Add`** and we are done setting up our policy, the next step is optional, so we click on the **`Next: Tags`** to the next page, then click next again **`Next: Review`**, on the review page, we fill in our policy name, and description.
In mine case i named it **`nodebucket-s3-policy`**, and the description i wrote **`policy for s3 bucket for nodebucket`**, you can write yours to, it doesn't have to be the same as mine. Then we click on **`Create Policy`** to finish with our AWS Policy Creation.
![Done with creating AWS policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/722d4m8vlvm2tukxkixc.PNG)

After you will be re-drected to your policy dashboard, and you should see your policy name, and a note say your policy has been created.
![Done image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iw3bac18h350xu7btvej.PNG)

Now we have created our custom policy, we now need to create our user, and attach this policy to it, now why do we need to do that? Because once we are done creating the user, we are going to create or generate an **`Access Key`**, and **`Access Secret Key`**, which we can use to our Node.js application, and since we connected our policy to the user, our **`Access Key`**, and **`Access Secret Key`** will permission to `upload`, `delete` and `updates` files however we want, because that the permission we set on our policy. 
Hope you understood this.

Now that we have covered this part, in part 2, we will cover creating our user, and generating our **`Access Key`**, and **`Access Secret Key`**.