Search code examples
amazon-web-servicesdockeraws-cloudformationaws-fargateaws-cloudformation-custom-resource

AWS Fargate 502 Bad Gateway after initial load


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.


Solution

  • 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.