I'm running a Next.js application on an AWS Elastic Beanstalk environment using Apache and Node.js 22 on 64-bit Amazon Linux 2023. Most of the time, after running eb deploy, the instance crashes.
Issue
After deployment, the Elastic Beanstalk environment health transitions from Info to Severe, with the following message in the AWS console:
Environment health has transitioned from Info to Severe.
ELB processes are not healthy on all instances.
Application update in progress on 1 instance. 0 out of 1 instance completed (running for 5 minutes).
None of the instances are sending data.
ELB health is failing or not available for all instances.
When this happens (not with every deploy but most of them), the instance becomes unusable:
Context
.ebextensions/build.config
file to ensure the application builds and starts correctly during deployment:container_commands:
01_install_dependencies:
command: "npm install"
cwd: "/var/app/staging"
02_build_application:
command: "npm run build"
cwd: "/var/app/staging"
03_copy_build_to_current:
command: "cp -R .next /var/app/current/.next"
cwd: "/var/app/staging"
This was introduced to address previous issues with the application failing to start properly after deployment.
.ebextensions/httpd-proxy.config
to handle domain redirection, SSL, and backend proxying:files:
"/etc/httpd/conf.d/proxy.conf":
mode: "000644"
owner: root
group: root
content: |
<VirtualHost *:80>
ProxyPreserveHost On
ServerName myServerName
ServerAlias \
"*.myUrls" \
ProxyTimeout 60
ProxyPass / http://127.0.0.1:8080/ connectiontimeout=10 timeout=180
ProxyPassReverse / http://127.0.0.1:8080/
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log combined
LogLevel warn
<Location "/api/health">
SetHandler proxy:fcgi://127.0.0.1:8080
</Location>
</VirtualHost>
Troubleshooting Steps Taken
Questions
Edit
I've removed the build.config
and added a .platform/hooks/postdeploy/postdeploy.sh
file with
#!/bin/bash
npm install --production=false
It made the deploy way more stable but it just crash again for the first time in a week.