Skip to content

AWS App Runner health check failing when deploying Next.js container image from ECR

0

Hi, I’m trying to deploy a Next.js app to AWS App Runner using a Docker image that I built locally and pushed to Amazon ECR. The image builds and pushes fine, and App Runner can pull it successfully, but the deployment keeps failing during the health check step.

📋 Deployment logs (App Runner) [AppRunner] Successfully pulled your application image from ECR. [AppRunner] Provisioning instances and deploying image for publicly accessible service. [AppRunner] Performing health check on protocol HTTP [Path: '/api/healthz'], [Port: '3000']. [AppRunner] Health check failed on protocol HTTP [Path: '/api/healthz'], [Port: '3000']. [AppRunner] Deployment ... failed. Failure reason : Health check failed.

🐳 Dockerfile

---- Stage 1: builder ----

FROM node:22-alpine AS builder WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci COPY . . RUN npm run build

---- Stage 2: runtime ----

FROM node:22-alpine AS runner WORKDIR /app ENV NODE_ENV=production ENV PORT=3000 ENV HOSTNAME="0.0.0.0"

COPY --from=builder /app/.next/standalone ./

EXPOSE 3000 CMD ["node", "server.js"]

🚀 Deployment script I build and push the image with a PowerShell script using docker buildx build --platform linux/amd64, then push to ECR. Architecture checks show amd64. Static files are uploaded separately to S3 + CloudFront.

⚠️ The issue App Runner pulls the image fine. But the health check fails (both / and /api/healthz). My container exposes port 3000, but I’ve read App Runner defaults to port 8080 unless overridden.

❓ My questions Do I need to configure App Runner to use PORT=3000, or should I change my container to listen on 8080? For a Next.js standalone build, should I be running server.js like this, or is there a better entrypoint for App Runner? Any other common pitfalls with health checks and Next.js on App Runner?

❓ Additional concern: quotas or account restrictions I also came across information that App Runner deployments can fail if service quotas or account restrictions prevent new instances from launching.

🗂 Environment AWS Region: eu-west-2 Node.js version: 22-alpine App Runner source: ECR private repo Health check path tried: / and /api/healthz Thanks in advance 🙏

asked a year ago649 views

1 Answer
0

Based on your description, there are several potential reasons why your App Runner deployment is failing at the health check stage:

  1. Port Mismatch: This is likely the primary issue. Your container is configured to listen on port 3000, but App Runner might be expecting traffic on port 8080 by default. You have two options:
  • Configure App Runner to use port 3000 in your service settings
  • Modify your container to listen on port 8080 instead
  1. Health Check Path: Ensure that your Next.js application actually has a /api/healthz endpoint that returns a 200 OK response. If this endpoint doesn't exist or returns a non-200 status code, the health check will fail. You might need to create this endpoint in your Next.js app.

  2. Application Startup Time: If your Next.js application takes longer to initialize than the health check timeout allows, the check might fail. Consider adjusting the health check timeout and interval settings in your App Runner configuration.

  3. Environment Variables: Verify that all necessary environment variables are properly set in your App Runner configuration, especially if your application requires specific variables to function correctly.

  4. Network Configuration: Make sure your application is binding to 0.0.0.0 (which you've set with HOSTNAME="0.0.0.0") to accept connections from outside the container.

For Next.js specifically with App Runner:

  • The standalone output from Next.js should work fine with your current approach of running node server.js
  • Make sure your Next.js app is properly handling the health check path
  • Consider adding a simple health check endpoint in your Next.js app if you haven't already

Regarding your concern about quotas or account restrictions - while this is possible, it's less likely to be the issue since you're seeing specific health check failures rather than provisioning failures. The logs indicate that App Runner is able to pull your image and attempt to deploy it, suggesting that quota issues aren't the primary problem.

I recommend first addressing the port configuration issue by either:

  1. Updating your App Runner configuration to specify port 3000, or
  2. Modifying your Dockerfile to use port 8080 (change both the ENV PORT and EXPOSE directives)
    Sources
    Why has Aws Runner failed to deploy the image even though it is working fine my local machine and everything configured properly | AWS re:Post
    Why is registered target health check failing | AWS re:Post
    Failure management - Container Build Lens

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.