AWS Elastic Beanstalk Node.js Deployment: Complete Step by Step Guide
By Braincuber Team
Published on March 23, 2026
Building and managing applications on the cloud can be a daunting task. This is especially true when it comes to handling different environments, scaling, and deploying updates. But there's a service in AWS that can simplify this process significantly.
AWS Elastic Beanstalk is here to make your life easier. It provides an easy-to-use platform for deploying, managing, and scaling your applications in the AWS Cloud, allowing you to focus on writing code while AWS handles the infrastructure complexity.
What You'll Learn:
- What is AWS Elastic Beanstalk and how it simplifies cloud deployment
- How to prepare Node.js source code for Elastic Beanstalk deployment
- Environment variable configuration and RDS database setup
- Step-by-step Elastic Beanstalk application creation process
- Best practices for production deployments and scaling
What is Elastic Beanstalk?
AWS Elastic Beanstalk is a fully managed service that helps you deploy, manage, and scale applications on AWS. It takes care of provisioning the required resources, such as EC2 instances, RDS databases, and load balancers.
Automatic Resource Provisioning
Elastic Beanstalk automatically provisions EC2 instances, RDS databases, load balancers, and other necessary infrastructure components for your application.
Managed Operations
Handles application deployment, monitoring, and maintenance tasks automatically, allowing you to focus on writing code and delivering features.
CloudFormation Integration
Uses CloudFormation to provision resources automatically, so you don't need to write CloudFormation templates yourself.
Auto-Scaling Support
Automatically scales your application based on traffic patterns, ensuring optimal performance and cost efficiency.
How to Prepare the NodeJS Source Code
We cannot deploy our app straight to Elastic Beanstalk. We need to follow a few preparation steps to ensure successful deployment. Here's how to prepare your Node.js application:
Configure package.json Start Command
Ensure your package.json file has the start command. Beanstalk executes npm start by default and throws an error if it can't find it. This is crucial for application startup.
Configure RDS Environment Variables
AWS follows pre-defined environment variables for RDS connections. Use RDS_HOSTNAME instead of DB_HOSTNAME for database hostname configuration to ensure proper connectivity.
Configure Application Port
Elastic Beanstalk runs on port 8080 by default. Configure your app to run on port 8080 and add the port number to environment variables for flexibility.
Add .ebextensions Configuration
Create a .ebextensions folder in project root with configuration files to help Elastic Beanstalk read environment variables properly during deployment.
Install Dependencies and Zip Code
Run npm install to install dependencies, then zip your code including node_modules. Ensure package.json is in the root folder for successful deployment.
{
"name": "my-node-app",
"version": "1.0.0",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "^4.18.0"
}
}
commands:
setvars:
command: /opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export (.key)="(.value)""' > /etc/profile.d/sh.local
packages:
yum:
jq: []
Critical Folder Structure
The zipped file should contain all files in the root folder, not inside any subdirectories. Elastic Beanstalk looks for package.json in the root folder and will fail if it can't find it.
| RDS Environment Variables | Purpose | Example |
|---|---|---|
| RDS_HOSTNAME | Database hostname | mydb.xxxxxx.us-east-1.rds.amazonaws.com |
| RDS_PORT | Database port | 3306 |
| RDS_DB_NAME | Database name | ebdb |
| RDS_USERNAME | Database username | admin |
| RDS_PASSWORD | Database password | [auto-generated] |
How to Create the Elastic Beanstalk App
Now that our source code is prepared, let's create the Elastic Beanstalk application. This process involves multiple configuration steps that need to be done carefully.
Configure Your Environment
Navigate to AWS Management Console, select Elastic Beanstalk, click Create Application. Choose Web server environment, provide app name, select Managed platform with Node.js, and upload your zip file.
Configure Service Access
Create two IAM roles - one for Elastic Beanstalk service and one for EC2 instances. Use Create and use new service role for Elastic Beanstalk, and create EC2 instance profile with appropriate permissions.
Set Up Database and Networking
Enable database toggle, choose MySQL engine, and configure database settings. Be careful with database deletion policy - choose Create Snapshot or Retain for production databases.
Configure Instance Traffic and Scaling
Configure load balancer settings and auto-scaling options. For development, Single instance preset is fine, but use High availability for production environments.
Configure Updates, Monitoring and Logging
Choose Basic health reporting, uncheck Managed updates activation, add your environment variables, and review all configurations before proceeding with deployment.
npm install
zip my-app.zip -r ./
Development Environment
Use Single instance preset for development and testing. This provides a simple setup with minimal cost for development purposes.
Production Environment
Always use High availability preset for production. This provides load balancing and auto-scaling capabilities for reliable production deployments.
Deployment Patience Required
Elastic Beanstalk deployment takes time to provision RDS and other resources. It can take 10-15 minutes, so be patient and avoid making frequent changes that require re-deployment.
Frequently Asked Questions
Why does my Node.js app fail to start on Elastic Beanstalk?
The most common issue is missing the start command in package.json. Elastic Beanstalk executes npm start by default. Also ensure your app listens on port 8080 or uses the PORT environment variable.
How do I connect my Node.js app to RDS database?
Use AWS pre-defined environment variables like RDS_HOSTNAME, RDS_PORT, RDS_DB_NAME, RDS_USERNAME, and RDS_PASSWORD. These are automatically populated when you enable database in Elastic Beanstalk.
What's the difference between Single instance and High availability?
Single instance runs one EC2 instance without load balancer, suitable for development. High availability includes load balancer, auto-scaling, and multiple instances across availability zones for production reliability.
How do I deploy updates to my Elastic Beanstalk application?
Upload a new version of your zip file through the Elastic Beanstalk console. You can deploy updates with zero downtime using rolling deployments or blue/green deployments for production environments.
What happens to my database if I delete the Elastic Beanstalk environment?
It depends on your database deletion policy setting. Delete removes the database permanently, Create Snapshot creates a backup before deletion, and Retain keeps the database running even after environment deletion.
Ready to Deploy Your Node.js Applications?
Congratulations! You've learned how to deploy Node.js applications with RDS database using AWS Elastic Beanstalk. This powerful service simplifies the deployment and management process, allowing you to focus on developing and scaling your applications.
Remember that Elastic Beanstalk handles the infrastructure complexity while you maintain control over your application code and configuration. Start with development environments and gradually move to production as you become comfortable with the platform.
