0
votes

I've been following a Fargate/docker tutorial here: https://medium.com/containers-on-aws/building-a-socket-io-chat-app-and-deploying-it-using-aws-fargate-86fd7cbce13f

Here is my Dockerfile

FROM mhart/alpine-node:15 AS build
WORKDIR /srv
ADD package.json .
RUN yarn
ADD . .

FROM mhart/alpine-node:base-9
COPY --from=build /srv .
EXPOSE 3000
CMD ["node", "index.js"]

I have two Fargate stacks

production was created from the AWS CloudFormation public-service template

chat was created from the AWS CloudFormation public-vpc template with some parameter substitutions from the tutorial:

enter image description here

The production stack exposes a valid ExternalUrl output parameter

enter image description here

When I open the URL, I can see a successful initial load of the index

enter image description here

But resources respond with a 502 (Bad Gateway)

enter image description here

And if I refresh the URL, the index throws the error as well

enter image description here

I'm new to AWS and Fargate. Are there server logs I should check? Could this be a problem with either of the templates (public-vpc.yml or public-service.yml) that I used for setup? Any help is appreciated — thank you.

2
The two templates you've linked are used as in - no modifications were performed allowing for reproduction of the issue? - Marcin
@Marcin I modified the following fields on public-service.yml as per the tutorial: ContainerPort, DesiredCount, ImageUrl, ServiceName, StackName — no fields were modified on public-vpc.yml - Paul
For the logs, you can go to CloudWatch and check it. - Franxi Hidro
I run the templates with chat container. I have no issues, all work as expected. Could you describe in more details what exactly are you doing, how are you testing the chat app? - Marcin

2 Answers

0
votes

Looks like your health checks are failing and so the instance is being stopped. You can validate that by navigating to ECS -> Clusters -> (Cluster) -> (Service) -> Tasks -> Stopped - this will show the list of containers that have recently been stopped and why.

I haven't dug through the CloudFormation, but I bet that the mapping of the Health Check to the container port is wrong.

0
votes

Mystery solved! Thank you @Marcin and @cynicaljoy for your help. @cynicaljoy, I checked the ECS cluster status, but there was nothing out of the ordinary — the chat task was RUNNING.

@Marcin, I followed your lead and re-created the stacks and app. Now it works! My issue was neglecting to match up the correct regions in all of my AWS commands the first time around. Some were run with us-west-1 and some with us-west-2. Once I matched those up, the gateway problem went away.