Elastic Beanstalk - Deploy NodeJS Application in Just 5 Steps
With an AWS Elastic Beanstalk service, we can deploy and scale web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.
We can simply upload our code and Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, and auto-scaling to application health monitoring. At the same time, you retain full control over the AWS resources powering your application and can access the underlying resources at any time.
In this post, we will cover the commands required to deploy the nodejs express server to different elastic beanstalk environments.
The first step is to set up elastic beanstalk application and then create environment like dev,stage and prod.
Make sure that elastic beanstalk is installed and eb command is working fine.
$ eb --version
EB CLI 3.20.3 (Python 3.7.1)
Step 1: Create a user for eb administrator access and keep the Access Key and Secret key with you.
Step 2: Configure eb with AWS credentials. Here we are creating AWS profile for Elastic Beanstalk.
$eb init --profile deploy-eb
Step 3: Goto the directory of your nodejs application , Creates a new environment as dev(by default it will create dev)
$eb create
Step 4: If any changes to code and you want to deploy your source code to the environment then use the below command.
$eb deploy
Step 5: If you want to set some environment variables(same we provide in .env file) then use below command
$eb setenv <variable name>=<value>
$eb setenv PORT=4545
Step 6: To enable cloudwatch logs for elastic beanstalk environment then use command
$eb logs --cloudwatch-logs enable
To terminate the eb just run the below command.
Note: Use this command only when you are certain for the destruction of whole stack created with eb.
$eb terminate
Other commands that can make your job easy
$eb scale
Changes the number of running instances.
$eb health
Shows detailed environment health.
$eb ssh
Opens the SSH client to connect to an instance.
$eb status
Gets environment information and status
$eb upgrade
Updates the environment to the most recent platform version
The sample nodejs express server code can be cloned from this GitHub repository - Sample NodeJS Application.

Comments
Post a Comment