Search code examples
amazon-web-servicesdockernginxaureliaamazon-elastic-beanstalk

Aurelia, Docker, Nginx, AWS Elastic Beanstalk Showing 502 Bad Gateway


I've deployed an Aurelia application to AWS Elastic Beanstalk via AWS ECR and have run into some difficulty. The docker container, when run locally, works perfectly (see below for Dockerfile).

FROM nginx:1.15.8-alpine

COPY dist /usr/share/nginx/html

The deployment works quite well, however when I navigate to the AWS provided endpoint http://docker-tester.***.elasticbeanstalk.com/ I get 502 Bad Gateway nginx/1.12.1.

I can't figure out what might be the issue. The docker container in question is a simple Hello World example created via the au new command; it's nothing fancy at all.

Below is my Dockerrun.aws.json file

{
  "AWSEBDockerrunVersion": "1",
  "Image": {
    "Name": "***.dkr.ecr.eu-central-1.amazonaws.com/tester:latest",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": "8080"
    }
  ],
  "Logging": "/var/log/nginx"
}

My Elastic Beanstalk configuration is rather small with an EC2 instance type of t2.micro. I'm using the free tier as an opportunity to learn.

I greatly appreciate any help, or links to some reading that may point in the right direction.


Solution

  • It has nothing to do with your aurelia application. You are missing EXPOSE statement (which is mandatory) in your Dockerfile. You can change it like this.

    FROM nginx:1.15.8-alpine
    
    EXPOSE 80
    
    COPY dist /usr/share/nginx/html
    

    If you try to run it without EXPOSE, you will get an error

    ERROR: ValidationError - The Dockerfile must list ports to expose on the Docker container. Specify at least one port, and then try again.
    

    You should test your application before pushing it to ElasticBeanstalk

    install eb cli (assuming that you have pip, if not then you need to install it as well)

    pip install awsebcli --upgrade --user
    

    then initialize local repository for deployment

    eb init -p docker <application-name>
    

    and you can test it

    eb local run --port <port-number>