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 code repository
Automatic
script/ci
(this runs an npm install
)script/run
(this just starts the node app)4200
Default
Default (I tried various settings without success)
Use an AWS-owned key (no Instance role)
Public access
none
Tags
none
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
.