Node with TypeScript: How to configure automatic deploy on AWS with Elastic Beanstalk
For this article, I want to demonstrate how to set up automatic deploys of a Node.js application with TypeScript on the AWS Cloud, using Elastic Beanstalk. In this way, this article will be like a tutorial, a little more direct, like a sequence of steps.
To start, you will need to have an AWS account, it is a project working correctly. I will use this repository as an example.
On the AWS console, look for Elastic Beanstalk, and create your application as shown in the image below:
After creating the application, create a new environment in the sequence of images below:
Add a domain and check its availability in the region where you are working
Now, wait for the EC2 instance creation process to finish.
Once completed, you will see in the environment settings of your application that it was successful, and something is already running.
Now, let’s set up a pipeline to get our project repository. We will use the CodePipeline that you can access on the console, as shown below:
In the image below, connect to your Github repository:
Now choose which branch will receive Github events that will be sent to the pipeline. Be careful when choosing.
In this case, I will use the “master” branch, and any commit made on the master, the pipeline will be executed.
At this point, let’s skip the build configuration.
Now let’s wait for the pipeline to run for the first time.
After finishing, just click on the Elastic Beanstalk link to return the environment settings of our application.
We can see that our application did fail to upload the code directly from the master branch repository.
In this repository, we have a health route to get the status of the application, and it really isn’t working.
We were able to analyze the application logs as shown in the image below:
We were able to identify that we did not compile TypeScript. So, let’s edit our application’s package.json to execute the build in the “start” script.
After committing our change to the “dev” branch, and making a merge request to the “master” branch, we can see that the pipeline received an update event, and is automatically running a new deploy.
Let’s access the host of our application again:
We realized that our application is working now. Let’s configure the health route to monitor the health of our application.
Let’s access the settings as shown below:
Add a new process to detect the health route in HTTP / 80 and HTTPS / 443.
Now we can confirm that the status of our application is all ok and everything is still working.