Deploy your Node.js app in matter of minutes using AWS Elastic Beanstalk
Tags: aws, beanstalk, node
Published: 2023-07-02 09:49:03

Have you ever wanted to deploy your app without so much hassle and have AWS manage everything for you and save your precious time? 🤔

then you probably would want to check out this tutorial on how to benefit from **AWS Elastic Beanstalk** which will handle the deployment, from capacity provisioning, load balancing, and automatic scaling to web application health monitoring, with ongoing fully managed patch and security updates.

In this tutorial we will be deploying a Node.js app but AWS Elastic Beanstalk supports many other platforms which are Java, .NET, PHP, Python, Ruby, Go, and Docker.

**Prerequisites**

- 
 AWS Account, if you don't have one yet, you can create a new AWS account, go to [aws.amazon.com](https://aws.amazon.com/) and choose [Create an AWS Account](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&src=header_signup&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start).


- Node.js app and ensure your `package.json` file has the `start command` and this start command should be configured to run your app, Beanstalk will execute npm start by default and it throws an error if it can't find it, if you don't have your own app to follow along in this tutorial, you can use this [sample app](https://download.wetransfer.com/eugv/46bb9399900a97dafcdc52cd50e6acf520230702074937/11e1d703c6c4e72fb2c1ebcb27a24cd00a66f6af/nodejs.zip?cf=y&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRlZmF1bHQifQ.eyJleHAiOjE2ODgyODQ4MTEsImlhdCI6MTY4ODI4NDIxMSwiZG93bmxvYWRfaWQiOiJhMjFhNWQwMC03MzY5LTRlNDEtYjRkNy02NmNiZGQ5MmQ0MjUiLCJzdG9yYWdlX3NlcnZpY2UiOiJzdG9ybSJ9.Bv9vEOQjmub0dSJIm7ANH-0EJq-RJLnk2TLMPYCsWH0).

---


**Step 1**

- Login in your AWS Account and go to your AWS Management Console from [here](https://aws.amazon.com/console/) .
- Navigate to AWS Elastic Beanstalk service inside your AWS management console search bar.
![AWS Beanstalk in search bar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/guj9hni25phjjni7jmc0.png)
- Click on Create Application.
- Choose your Application name and choose the correct platform which in our case will be Node.js 

![Choose app name and platform](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/se542trces6fpgl2kz70.png)
- Choose to upload your own local code and type a version label for it then choose which instances preset you need for your app, in this tutorial we will go with a single instance (Free tier)

![upload your code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bvfkzas5doxbu6r5px3d.png)


---

**Step 2**

- Configure service access, select Create and use new service role. It'll automatically create and provide required permissions

- To access your EC2 instance through the terminal using SSH, you should generate a key-value pair and choose it. However, if you don't need to log in to EC2, you may skip this step.

- Next, you should create an IAM role with the required permissions: 

    `AWSElasticBeanstalkWebTier
    AWSElasticBeanstalkWorkerTier
    AWSElasticBeanstalkMulticontainerDocker`

- Assign the role to the "EC2 instance profile" and then move on to the following step.

---


**Step 3**

- Configure your network, Select your VPC then for instance settings Activate Public IP Address if you want to SSH into the instance and then choose a subnet in the availability zone you need, for the database settings you can skip it since you don't need to configure the database for this sample app but if your app needs it you can simply enable the database settings and fill in the database info.


![Network Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rfuoe3f0gn9vx22x78xc.png)

---


**Step 4**


- Configure your storage and scaling, select your desired root volume type, you can keep it on the container storage default since it's the most optimal option, then choose your needed security group for the instance.

![storage and scaling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zeaumllkpkmurf9i80zo.png)

- Configure Auto scaling group, for this tutorial we chose single instance to just showcase a sample app deployment but in production you would probably need to enable load balancing and fill in the information based on your needs.

---


**Step 5**

- Configure updates, monitoring, and logging, you can leave this with the default options enabled or adjust the settings depending on your needs.

---

**Step 6**

- Review your Application settings before deployment and when you are done you can just go ahead and click on submit.



---

Now just wait  till your application is deployed 😎 which will approximately take about 5 minutes.

Good job 🎉 :clap: for following along and reaching the end of the tutorial now  you can click on the domain link provided by Elastic Beanstalk to see your sample node.js app running.


![app link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fmxtdid0ky627g3vjs92.png)
---
---


![node app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78cv33hu3qr8ugukxlsn.png)



**BONUS**

:male_detective: Would you like to know what actually happened behind the scenes in AWS Elastic Beanstalk to deploy your app?  

Well it's pretty simple, AWS creates a CloudFormation stack to deploy your application with the configuration you provided in the previous steps which is pretty cool since you can see exactly how everything got deployed and even re-use that stack and adjust your own configuration on the fly!



That's a wrap for the tutorial, thank you for taking your time to check it out and I hope you found it helpful and if you ever have any questions or feedback you can write it down in the comments.

See you later in another tutorial ! 👋