1

I'm trying to run an old Node.js project in AWS Elastic Beanstalk. It sometimes crashes and the environment health goes to "Degraded," but instead of restarting the container, EB just leaves it hanging.

Looking at the logs, it appears that the container exits due to some socket.io error.

This question has been asked before, but this answer, this answer, and this reddit comment all suggest configuring a load balancer. However, I have a single-instance application and I have no load balancer at all.

Is it possible to have EB restart single-instance applications automatically?

dodov
  • 5,206
  • 3
  • 34
  • 65

2 Answers2

0

A ELB (Load Balancer) can be used even with only one instance and might things easier if you want to scale-out in the future or consider other deployment strategies. So there is no technical harm in using one (except that it cost more, but that's financially).

Augunrik
  • 1,866
  • 1
  • 21
  • 28
  • Well, I care about the cost. I don't want to pay for a load balancer that "distributes" traffic between just a single instance. Is there a way to have EB restart instances without an ELB? – dodov Mar 11 '23 at 05:38
  • If you do care about costs too much, you should question using AWS altogether. It sucks you in and sells you additional services. --- On Topic: You can always create an cloudwatch alarm that schedules a custom lambda/step function which restarts Beanstalk. – Augunrik Mar 11 '23 at 08:51
0

Instead of restarting the entire EB Application it's better to Dockerize the app, and restart the Docker itself when it failed.

  1. Set the Restart policy in the Dockerfile as following
    CMD ["apache2ctl", "-D", "FOREGROUND", "--restart=on-failure"]
  1. Dockerrun.aws.json file and deploy the code using EB CLI
    {
      "AWSEBDockerrunVersion": "1",
      "Image": {
        "Name": "<your-image-name>"
      },
      "Ports": [
        {
          "ContainerPort": "80"
        }
      ],
      "RestartPolicy": {
        "Name": "on-failure",
        "MaximumRetryCount": 5
      }
    }
Sri
  • 342
  • 4
  • 17