简体   繁体   中英

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

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 EXPOSE d:

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

Make sure that you have a health check endpoint that returns 200 OK . Next will return 304 s 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 200 s instead of 304 NotModified .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM