

Deploying Your Node API to AWS Using Elastic Beanstalk (Demo Project)
source link: https://vkontech.com/deploying-your-node-api-to-aws-using-elastic-beanstalk-demo-project/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Intro
This article is a step-by-step guide on setting up and deploying a sample Node JS application on AWS using Elastic Beanstalk.
I completed this project as part of the Cloud Developer Nanodegree at Udacity. You can find the source code on GitHub.
You will walk through the following steps:
- Run the Node project locally
- Set up the AWS CLI, users, and permissions
- Set up Elastic Beanstalk
- Build and deploy the application
- Consume the publicly accessible endpoint via Postman
About the Nanodegree
The Nanodegree will train you in critical AWS skills to become an effective cloud developer.
Some of the covered topics are:
- Cloud Computing in AWS
- Storage & Content Delivery
- Cloud Security
- Networking & Elasticity
- Deployments via AWS Elastic Beanstalk
- Microservices Design Principles
- Messaging & Containers, Docker
- Containers orchestration with Kubernetes in AWS
- Serverless apps, Lambda functions, Auth
Each of the main sections of the Nanodegree ends with a small project where you can interactively put your knowledge into action.
Also, you’ll get to complete a final Capstone project putting together most of the concepts you go through during the learning journey.
Don’t let the pricing discourage you – at the time I took the Nanodegree, every customer could use a discount coupon that reduces the cost by up to 90%!
Project Overview
The business logic is not that important as the main focus is on deploying and running the project in AWS.
The functionality is quite simple.
There’s a single API endpoint where you pass some public image URL, and you get back a “normalized” version of the image e.g. converted to grayscale and resized to some standard dimensions. This can potentially be used in a Computer Vision pre-processing pipeline.
Let me help you get a better sense of this.
Imagine you have some image like this one:
You can use the deployed service and pass the image public URL to get a result like this:
Run Locally
Running the project on your local machine is quite simple.
After you’ve cloned the repo, you first need to install the Node dependencies via npm install
Then, execute npm run dev
to start your local API on port 8082:
You can do another test with Postman on localhost
, making sure everything works as expected:
Let’s move towards the AWS deployment.
Setup the AWS IAM User
In order to use Elastic Beanstalk to deploy your app, you need a user with the appropriate permissions. I advise against using your root user even for demo purposes.
Go to the IAM dashboard and start creating a new user. Check the Programmatic access checkbox.
Then attach the Elastic Beanstalk Admin policy:
Once you’re done with this, download the user credentials via the Download .csv button. This will be needed to set up the AWS CLI.
Install the AWS CLI
Now, you need to install the AWS CLI. Find the installation steps for your environment here.
Set Up the AWS CLI with the IAM User Credentials
You should then configure your AWS CLI to work with the user you just created. Refer to the downloaded .csv file to find the Access Key ID and the Secret Access Key to do so:
I have already deleted this user. Make sure these secrets are not shared with anyone!
Build and Deploy to AWS
In this section, we’ll go through the steps of building, deploying, and running your app in AWS.
Install Elastic Beanstalk CLI
First, you need to install the Elastic Beanstalk CLI following these steps.
In essence, you have to clone a git repo and run a python script that will automate the setup for you:
Once the installation is successful, you should add the EB CLI to your PATH variable. I am using WSL2 with Ubuntu on my Windows machine, so this means executing the following:
echo 'export PATH="/home/vasilkosturski/.ebcli-virtual-env/executables:$PATH"' >> ~/.bash_profile && source ~/.bash_profile
Generate an EC2 Key Pair
A public/private key pair allows you to prove your identity when connecting to the EC2 instances provisioned for your Elastic Beanstalk application. The public key is stored on the EC2 instance, and you keep the private key. Then, you can use the private key to securely login via SSH.
For instructions on creating a key pair, see Creating a Key Pair Using Amazon EC2.
Here’s a screenshot from my setup:
Build and Produce Deployment Artifacts
It’s time to build the project by running npm run build
in your local directory.
This will do the following:
- Transpile Typescript
- Collect the source files
- Produce an archive
After the build is successful, you should see the following www
output directory:
We’ll use the Archive.zip
file to deploy the project via Elastic Beanstalk. You’ll see how to do that in a later section.
EB Init
You need to set up Elastic Beanstalk for the project using the eb init
command.
In the screenshots below, you’ll see the steps to go through. For some of them, I’ve just used the default options by hitting Enter.
At this point, you should have a new directory named .elasticbeanstalk
with a file config.yml
We’re using an artifact-based build project, so you need to add a reference to the Archive.zip
file as shown below.
EB CLI – Create Environment
Now that we have the EB configuration for the project, it’s time to do the actual deployment using the eb create
.
This launches an environment in AWS and deploys your app there.
Consuming the API
You can now navigate to the Elastic Beanstalk dashboard and see the newly created application. There, you will spot the public URL, which can be used to invoke your API.
Using Postman (or any other HTTP client), you can test your new API. In my case, I’m sending a GET request to the following URL:
You can get the Postman collection from the GitHub repo.
Summary
This article was a quick demo of how to deploy your Node API to AWS using Elastic Beanstalk.
I hope you found it useful!
See you next time!
Resources
Recommend
-
48
There is no doubt that AWS is still a hot topic in 2019 so I felt that I should write something useful to get started with exploring it’s capabilities. In this tutorial I’ll show you how to deploy a simple Spring Boot app...
-
24
AWS Elastic Beanstalk 增加了对 PHP 7.3 和 .NET Core 3.0 的支持 发布于: Oct 29, 2019 您现在可以使用 PHP 7.3 和 .NET Core 3.0 开...
-
5
To deploy your Spring Boot app in the web it really takes only 5 minutes thanks to AWS Elastic Beanstalk. For the deploy we can choose multiple sources: code, docker image or deployable jar/war. In this example we shows the deploy thr...
-
11
In this article, we will go through the process of setting up an Elastic Beanstalk Environment, creating a new Laravel application, deploying the application to your Elastic Beanstalk Environment, and setting up a database for it. Pr...
-
6
Deploying app in Elastic Beanstalk using EB CLI Reading Time: 5 minutes Hello Readers! In t...
-
9
A Comprehensive Guide to Deploying Laravel Applications on Aws Elastic Beanstalk When it comes to deploying web applications on the cloud, AWS Elastic Beanstalk is one of the most popular choices. It is a plat...
-
4
Deploying a Node.js App with AWS Elastic Beanstalk Amazon's Elastic Beanstalk makes it easy to deploy and scale your applications with load balancing, health monitoring, and au...
-
5
Deploying a Django Application to Elastic Beanstalk Amazon's Elastic Beanstalk service makes deploying and managing high-availability web applications on AWS easier. In th...
-
13
Have you been looking for a way to deploy React applications to AWS Elastic Beanstalk? If so, then this tutorial is for you. In this tutorial, you will crisply build a React ap...
-
9
Deploying a Spring Boot app to AWS Elastic Beanstalk with the eb cli Deploying a Spring Boot app to AWS Elastic Beanstalk is relatively easy using the eb...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK