Search code examples
amazon-web-servicesdockernpmamazon-ecs

Node app docker image runs locally and fails on Amazon ECS


The app deploys and runs just fine locally for long periods of time without issue. On Amazon ECS, however, it seems to always crash after running idle for roughly 2:30 min. What's wrong?

Dockerfile

# Set the node alpine base image
FROM node:15-alpine

# Establish app working directory
WORKDIR /app

# Setup app workspace
COPY app.js .
COPY package.json .
COPY package-lock.json .

COPY app/ app

# Install app dependencies
RUN npm install

# Document listener port
EXPOSE 80

# Run listener
CMD [ "npm", "start" ]

Amazon ECS task logs

2021-06-05 17:33:20     npm ERR! A complete log of this run can be found in:
2021-06-05 17:33:20     npm ERR! /root/.npm/_logs/2021-06-05T15_33_20_563Z-debug.log
2021-06-05 17:33:20     npm ERR! command failed
2021-06-05 17:33:20     npm ERR! signal SIGTERM
2021-06-05 17:33:20     npm ERR! command sh -c node app
2021-06-05 17:33:20     npm ERR! path /app
2021-06-05 17:33:20     npm notice
2021-06-05 17:33:20     npm notice New minor version of npm available! 7.7.6 -> 7.16.0
2021-06-05 17:33:20     npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.16.0>
2021-06-05 17:33:20     npm notice Run `npm install -g [email protected]` to update!
2021-06-05 17:33:20     npm notice
2021-06-05 17:30:50     Server started at 0.0.0.0:80 ..
2021-06-05 17:30:46     > [email protected] start
2021-06-05 17:30:46     > node app

Solution

  • The issue was with the ELB Health Check. The default location for the health check was on path '/', and due to the design of the web app, that location was not returning 200 OK. Configuring the health check path to something that returns 200 OK solved the issue. Also, considering the health check grace period on the ECS service can be relevant too in some instances.