morras
morras

Reputation: 1230

Elastic beanstalk deployed via cloudformation does not update health check target

I have an Elastic Beanstalk environment deployed via CloudFormation.

For now it is a single webserver behind a LoadBalancer, but this will expand with an auto scaling group in the future.

Here are the relevant snippets from my template

"BeanstalkEnvironment": {
    "Type": "AWS::ElasticBeanstalk::Environment",
        "Properties": {
        ...
            "OptionSettings": [
                ...
                {
                    "Namespace": "aws:elasticbeanstalk:application",
                    "OptionName": "Application Healthcheck URL",
                    "Value": "/health"
                },
                {
                    "Namespace": "aws:elasticbeanstalk:environment",
                    "OptionName": "EnvironmentType",
                    "Value": "LoadBalanced"
                },
                {
                    "Namespace": "aws:elasticbeanstalk:environment",
                    "OptionName": "LoadBalancerType",
                    "Value": "application"
                },
                {
                    "Namespace": "aws:elbv2:listener:default",
                    "OptionName": "ListenerEnabled",
                    "Value": "true"
                },
                {
                    "Namespace": "aws:elbv2:listener:443",
                    "OptionName": "ListenerEnabled",
                    "Value": "true"
                },
                {
                    "Namespace": "aws:elbv2:listener:443",
                    "OptionName": "Protocol",
                    "Value": "HTTPS"
                },
                {
                    "Namespace": "aws:elbv2:listener:443",
                    "OptionName": "SSLCertificateArns",
                    "Value": {"Ref": "Certificate"}
                },
                {
                    "Namespace": "aws:autoscaling:asg",
                    "OptionName": "MinSize",
                    "Value": "1"
                },
                {
                    "Namespace": "aws:autoscaling:asg",
                    "OptionName": "MaxSize",
                    "Value": "1"
                }
                ...
            ],
            "SolutionStackName": "64bit Amazon Linux 2 v3.0.3 running PHP 7.4",
        ...
        }
    }
}

The load balancer target group is still using / as the path for the health check. Since my web server redirects / the health check fails because it does not get the required 200 status code.
If I manually change the target path to be /health then the health check works as expected.

What configuration am I missing to be able to set the health check path as part of the CloudFormation template for the environment?

Upvotes: 1

Views: 1344

Answers (2)

Marcin
Marcin

Reputation: 238051

I think this setting aws:elasticbeanstalk:application is for classic load balancer (CLB).

However, since you are using ALB (application load balancer) you should use aws:elasticbeanstalk:environment:process:default.

This option allows you to set (among other things):

  • HealthCheckPath: Path to which to send HTTP requests for health checks.
  • MatcherHTTPCode: A comma-separated list of HTTP code(s) that indicate that an instance is healthy.

Upvotes: 8

morras
morras

Reputation: 1230

Right after I posted the question I found the answer myself.

Specifically my problem was that I am using an application loadbalancer.

The Application Load Balancer health check doesn't use the Elastic Beanstalk health check path. Instead, it uses the specific path configured for each process separately. AWS Documentation

So I need to add a health check for the process that the application loadbalancer is forwarding to.
Luckily both my loadbalancer listeners are using the default process, so if I update the default process health check path, then it will work.

So I changed this OptionsSetting

{
    "Namespace": "aws:elasticbeanstalk:application",
    "OptionName": "Application Healthcheck URL",
    "Value": "/health"
},

to be

{
    "Namespace": "aws:elasticbeanstalk:environment:process:default",
    "OptionName": "HealthCheckPath",
    "Value": "/health"
},

instead. You can find this documented here

Upvotes: 2

Related Questions