Home > Mobile >  AWS App Runner health check fails even though appropriate port is exposed
AWS App Runner health check fails even though appropriate port is exposed

Time:10-10

I'm trying to deploy my application to AWS App Runner and even though everything seems okay it still fails to deploy because the health check fails. I'm trying to deploy from a source code repository so AWS builds an image for me. I checked the deploy logs and I can see the appropriate port being EXPOSEd:

10-08-2022 09:59:42 PM [Build] Step 5/5 : EXPOSE 4200

When the application starts I can see that it works properly and listens to connections on port 4200:

10-08-2022 10:02:49 PM [ ready ] on http://localhost:4200

yet I get this from App Runner:

10-08-2022 10:07:57 PM [AppRunner] Health check on port '4200' failed. Service is rolling back. Check your configured port number. For more information, read the application logs.

What am I doing wrong? I configured App Runner from the UI using the following parameters:

Source

Source code repository

Deployment Settings

Automatic

Build Settings

  • Runtime: Node 16
  • Build command: script/ci (this runs an npm install)
  • Start command: script/run (this just starts the node app)
  • Port: 4200

Auto Scaling

Default

Health Check

Default (I tried various settings without success)

Security

Use an AWS-owned key (no Instance role)

Networking

Public access

Observability

none

Tags

none

Possible Culprits

  • Maybe the protocol is wrong? It mentions a TCP health check but I serve an HTTP API
  • Maybe I need to set up a custom VPC instead of "Public access"? I tried the default VPC but it didn't work either

CodePudding user response:

Make sure that you have a health check endpoint that returns 200 OK. Next will return 304s in many cases that will mess with your health check. App Runner can't be configured unfortunately for a specific HTTP response code so you can do something like:

import { NextApiRequest, NextApiResponse } from "next";

const handler = (req: NextApiRequest, res: NextApiResponse) => {
    res.status(200).json({ ok: Date.now().toString() });
};

export default handler;

Note that a new Date is returned each time so you'll get 200s instead of 304 NotModified.

  • Related