Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the health-check URL on an Elastic Beanstalk instance in a AWS CloudFormation template?

I have a CloudFormation template that starts an Elastic Beanstalk service. I want to set the health-check URL to /health in the template.

What is the convention for this in JSON?

like image 529
sdgfsdh Avatar asked Dec 11 '17 12:12

sdgfsdh


2 Answers

You need to set the OptionSettings property of the AWS::ElasticBeanstalk::Environment:

For example:

{
   "Type" : "AWS::ElasticBeanstalk::Environment",
   "Properties" : {
      "ApplicationName" : { "Ref" : "sampleApplication" },
      "Description" :  "AWS Elastic Beanstalk Environment running PHP Sample Application",
      "VersionLabel" : "Initial Version",
      "OptionSettings" : [ 
            {
               "Namespace" : "elasticbeanstalk:application",
               "OptionName" : "Application Healthcheck URL",
               "Value" : "/health"
            }         
      ],      
      "TemplateName" : "DefaultConfiguration",
   }
}    

In this example, the option Application Healthcheck URL is set to /health

For more information see:

  1. AWS::ElasticBeanstalk::Environment
  2. Configuration Options
  3. ConfigurationOptionSettings
like image 110
Rodrigo Murillo Avatar answered Sep 28 '22 05:09

Rodrigo Murillo


Rodrigo's answer is good but incomplete.

You also need to modify the health_check_type to ELB, otherwise, when your web application process crash, but your EC2 instead remains healthy, the node won't get replaced.

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environmentconfig-autoscaling-healthchecktype.html

this is the format I am using

$ cat .ebextensions/0090_healthcheckurl.config 
Resources:
   AWSEBAutoScalingGroup:
     Type: "AWS::AutoScaling::AutoScalingGroup"
     Properties:
       HealthCheckType: "ELB"
       HealthCheckGracePeriod: "600"
option_settings:
  - namespace:  aws:elasticbeanstalk:application
    option_name:  Application Healthcheck URL
    value:  /_status

like image 22
Mathieu J. Avatar answered Sep 28 '22 04:09

Mathieu J.