AWS Deployment for Node.js | EC2, Elastic Beanstalk & Lambda Basics
이 글의 핵심
Pick EC2 for full control, Elastic Beanstalk for managed platforms, or Lambda for HTTP APIs—this guide covers bootstrap steps and how they fit a Node.js release flow.
Introduction
This section extracts AWS-focused deployment patterns from the broader Node.js deployment guide: EC2 for VMs you manage, Elastic Beanstalk for a managed platform, and Lambda for serverless HTTP handlers.
Deployment checklist (reminder)
- Environment variables configured
- Production-only dependencies installed
- Error logging enabled
- Security middleware (e.g. Helmet, CORS)
- Database migrations applied
- Static assets built
- Tests passing
- Load/perf smoke tests
Deployment styles:
- Traditional: VPS, PM2, Nginx
- Containers: Docker, Kubernetes
- Serverless: AWS Lambda, Vercel
- PaaS: Heroku, Railway, Render
1. EC2 deployment
1) Create an EC2 instance
- Choose Ubuntu Server (or your standard AMI)
- Security group: open HTTP (80), HTTPS (443), SSH (22) as needed
2) Server setup
# SSH in
ssh -i your-key.pem ubuntu@your-ec2-ip
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
# Git
sudo apt-get install -y git
# Clone project
git clone https://github.com/yourusername/your-repo.git
cd your-repo
# Dependencies
npm ci --only=production
# Environment
nano .env
# PM2
npm install -g pm2
pm2 start app.js --name "my-app" -i max
pm2 startup
pm2 save
# Nginx
sudo apt install -y nginx
sudo nano /etc/nginx/sites-available/myapp
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
2. Elastic Beanstalk
Install CLI
pip install awsebcli
Initialize and deploy
eb init
# Create environment and deploy
eb create production
eb deploy
# Logs
eb logs
# Environment variables
eb setenv NODE_ENV=production PORT=8080
# Status
eb status
# Tear down
eb terminate production
3. Lambda (serverless)
// lambda.js
const serverless = require('serverless-http');
const app = require('./app');
module.exports.handler = serverless(app);
serverless.yml:
service: my-app
provider:
name: aws
runtime: nodejs20.x
region: ap-northeast-2
functions:
app:
handler: lambda.handler
events:
- http:
path: /{proxy+}
method: ANY
cors: true
Deploy:
npm install -g serverless
serverless deploy
Conclusion
AWS options for Node.js span full control (EC2), managed platform (Elastic Beanstalk), and serverless (Lambda). Match operational maturity, traffic shape, and cold-start tolerance to the service. For PM2, Docker, and Nginx details, see the full Node.js deployment guide.