[2026] AWS Deployment for Node.js | EC2, Elastic Beanstalk & Lambda Basics
이 글의 핵심
Deploy Node.js on AWS: EC2 bootstrap with PM2 and Nginx, Elastic Beanstalk with eb CLI, and serverless Lambda with serverless-http—security groups, env vars, and rollout notes.
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
다음은 bash를 활용한 상세한 구현 코드입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
# 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
다음은 bash를 활용한 상세한 구현 코드입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
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)
아래 코드는 javascript를 사용한 구현 예제입니다. 코드를 직접 실행해보면서 동작을 확인해보세요.
// lambda.js
const serverless = require('serverless-http');
const app = require('./app');
module.exports.handler = serverless(app);
serverless.yml: 다음은 yaml를 활용한 상세한 구현 코드입니다. 각 부분의 역할을 이해하면서 코드를 살펴보시기 바랍니다.
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.