ECS containers securely routed via API Gateway not returning but health check on containers is good

Lew*_*ith 5 amazon-web-services amazon-ecs node.js docker aws-application-load-balancer

Okay so this is going to be a long one, but I want to make sure I explain. I am trying to do a proof of concept that we can deploy micro services via ECS that are exposed using API Gateway so we can leverage the lambda authorisers and cognito.

To achieve this I have been following this guide on Medium

However once I deploy my gateway I am faced with the following error:

Cannot GET /node-demo
Run Code Online (Sandbox Code Playgroud)

Let me go through the basics, I have a basic express application like so:

const express = require('express')

const PORT = process.env.PORT || 3000

const app = express()

app.get('/', (request, response) => {
  return response.json({
    data: {
      message: `API is functional`,
    },
  })
})

app.listen(PORT, () => console.log(`App running on port ${PORT}`))
Run Code Online (Sandbox Code Playgroud)

Dockerfile looks like this:

FROM mhart/alpine-node:10.16.3

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY index.js .

CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)

This docker image has been pushed to ECR, I have created a Task Definition with an environment variable PORT => 80

Created a service on my cluster which is working fine. Then created an ALB with a target group that points to my containers, these come back healthy!

健康的 ALB 目标

And I route to these targets with the following:

路由

My NLB then points to the ALB and I have allowed the correct IPs on the ALB so we can get to it through the security group. Both IPs in the NLB target group are healthy

Created a VPC link in API Gateway and then created a resource like the below:

应用程序接口

I then deploy hit the URL with /node-demo at the end and get the initial error above. Either the guide has a mistake or I've done something fundamentally wrong.

Lew*_*ith 0

好消息和坏消息,

好消息,我已经解决了这个问题。

坏消息,这非常简单

只需要向 Express 应用程序添加一条路线,

/node-demo