Production Node.js on AWS EC2: A Checklist
An EC2-specific checklist for running Node.js in production: networking, IAM, storage, TLS, email, monitoring and the decisions that keep a single instance dependable.
Most guides to "nodejs aws ec2 production" setups end once node server.js responds on port 80. That is the first ten percent. The rest is networking, identity, storage, email deliverability, monitoring and recovery, which is where production apps actually fail.
I ran a B2B marketplace on AWS EC2 that I built solo, and I run Node services on GCP VMs for Antoc. This checklist is the EC2-specific version of what I set up before real users arrive. If you are on Google Cloud instead, my post on deploying Next.js on GCP covers the equivalent setup.
TL;DR
Launch a right-sized instance in the region nearest your users, attach an Elastic IP, lock security groups to 80/443 plus restricted SSH, use IAM roles instead of stored keys, put Nginx in front for TLS, run the app under PM2 or systemd, send email through SES, and turn on EBS snapshots and CloudWatch alarms. Add load balancers later, when you have a reason.
key takeaways
- A single well-configured EC2 instance can run a Node.js product reliably for a long time if networking, IAM and backups are done properly.
- Use an Elastic IP, tight security groups and IAM instance roles instead of public SSH and access keys stored on disk.
- EBS snapshots, CloudWatch alarms and log rotation are the unglamorous parts that prevent most outages.
- Move to load balancers and auto scaling only when traffic or uptime requirements justify the extra moving parts.
The checklist at a glance
| Area | Do this | Why |
|---|---|---|
| Instance | Start with t3/t4g, 2 vCPU, 2 to 4 GB; gp3 EBS 30 GB+ | Cheap, and gp3 lets you tune IOPS separately |
| IP | Allocate and attach an Elastic IP | Public IP survives stop/start, DNS stays valid |
| Security group | 80/443 open, 22 from your IP only, app port closed | Users go through Nginx, attackers see less |
| Identity | IAM instance role with least privilege | No AWS keys in .env files |
| Metadata | Require IMDSv2 | Blocks a class of SSRF credential theft |
| TLS | Nginx + Certbot, auto-renew | Free certificates, HTTP/2, redirects |
| Process | PM2 with startup script, or systemd | Restarts on crash and reboot |
| Amazon SES with SPF, DKIM, DMARC | Deliverability without running a mail server | |
| Backups | Scheduled EBS snapshots via Data Lifecycle Manager | Point-in-time recovery for the whole disk |
| Monitoring | CloudWatch alarms, agent for memory and disk | Default metrics skip memory and disk usage |
Networking and identity
Elastic IP and DNS
An instance's auto-assigned public IP changes when you stop and start it. Allocate an Elastic IP, associate it, and point your A records at it. Remember that an Elastic IP not attached to a running instance costs money, so release ones you stop using.
Security groups
Treat security groups as your first firewall:
- Inbound 443 and 80 from
0.0.0.0/0(80 only to redirect to HTTPS). - Inbound 22 from your office or home IP, or close it entirely and use Session Manager.
- Database ports open only to the app server's security group, never to the internet.
- Outbound left open unless you have a reason to restrict it.
Reference security groups by ID instead of IP ranges where possible. When you add a second app server, it inherits access automatically.
IAM roles, not keys
If your app uploads to S3 or sends via SES, attach an IAM role to the instance. The AWS SDK picks up temporary credentials from the instance metadata service automatically. Long-lived access keys in an .env file are the thing you least want copied off a server. Enforce IMDSv2 so those credentials require a session token. AWS's EC2 user guide covers both.
Running the Node process
On the instance itself:
- Install Node with nvm or NodeSource, pinned to the version CI uses.
- Run the app as a non-root user. Bind to a high port (3000, 8000) and let Nginx listen on 80/443.
- Use PM2 with
pm2 startupandpm2 save, or a systemd unit withRestart=always. - Set
NODE_ENV=production, which changes Express behavior and many libraries' defaults. - Handle
SIGTERMgracefully: stop accepting connections, finish in-flight requests, close database pools, then exit. - Rotate logs with
pm2-logrotateor logrotate, because a full EBS volume takes down everything.
Nginx sits in front for TLS termination, gzip, upload size limits and WebSocket upgrades. Certbot with the Nginx plugin issues and renews certificates.
Email, monitoring and recovery
SES for transactional email
New SES accounts start in a sandbox that can only send to verified addresses. Request production access early, because approval can take a day or more. Verify your domain, publish SPF, DKIM and DMARC records, and handle bounces and complaints, or SES may pause sending.
What to monitor
CloudWatch gives CPU and network by default but not memory or disk usage. Install the CloudWatch agent or use another monitor, then alarm on:
- Disk above 80 percent.
- Memory pressure or swap usage.
- CPU credit balance near zero on burstable instances.
- Failed health checks from an external uptime monitor.
- Error rate spikes from your error tracker.
Recovery
Schedule daily EBS snapshots with Data Lifecycle Manager and keep a week or more. Snapshot before every risky change. Practice restoring: launch an instance from a snapshot in a test subnet and confirm the app boots. Databases deserve their own backup plan on top of disk snapshots.
How I built this in practice
On X4ET, a B2B tech marketplace I built solo, production ran on AWS EC2 with an Elastic IP, Nginx and SSL in front of a Next.js frontend and a FastAPI backend, with MongoDB for data. Four GitHub Actions runners handled deploys, Razorpay handled payments, AWS SES sent transactional email, and MSG91 delivered OTPs.
On the Antoc side, the same principles apply on GCP: VMs in asia-south1 running Node/Express and Next.js under PM2 behind Nginx, Sentry for errors, and a MongoDB database hardened with authentication and network restrictions as it grew past 300K leads. The cloud vendor changes the names (security groups versus firewall rules, Elastic IP versus static IP), not the checklist.
Across AWS, GCP and Azure, the projects that stayed calm were the ones where these basics were done before launch, not after the first outage.
Common mistakes
- Storing AWS access keys in
.envinstead of using an instance role. - Leaving SSH open to the world with password login enabled.
- Forgetting to request SES production access until launch day.
- Running a sustained-load API on a burstable instance and getting throttled when credits run out.
- Relying on default CloudWatch metrics and missing a disk filling up.
- Never testing a snapshot restore.
keep reading
FAQ
Is EC2 a good choice for a Node.js production app?+
Yes, for many SaaS products and APIs. EC2 gives full control, predictable pricing and room for background workers. Managed options like App Runner or Elastic Beanstalk reduce ops work but limit flexibility.
What EC2 instance type should I start with for Node.js?+
A burstable t3 or t4g instance with 2 vCPU and 2 to 4 GB RAM is a common starting point for small apps. Watch CPU credit balance, because a sustained-load app on a burstable instance can slow down when credits run out.
Should I use PM2 or systemd for Node.js on EC2?+
Both work. PM2 adds clustering, zero-downtime reloads and log handling for Node specifically, while systemd is built in and fine for a single process. I usually use PM2 for apps and systemd for supporting services.
How do I send email from a Node.js app on EC2?+
Use Amazon SES rather than running your own mail server. Verify your domain, set up SPF, DKIM and DMARC, request production access, and send through the SES API from the app using an IAM role.
Devang Gandhi
AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me