如何在 AWS CloudFormation 模板中对 Elastic Beanstalk 实例设置运行状况检查 URL?

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

我有一个启动 Elastic Beanstalk 服务的 CloudFormation 模板。我想在模板中将健康检查 URL 设置为 /health

JSON 中对此的约定是什么?

您需要设置 OptionSettings 属性 的 AWS::ElasticBeanstalk::Environment:

例如:

{
   "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",
   }
}    

在此示例中,选项 Application Healthcheck URL 设置为 /health

有关详细信息,请参阅:

  1. AWS::ElasticBeanstalk::Environment
  2. Configuration Options
  3. ConfigurationOptionSettings

Rodrigo 的回答很好但不完整。

您还需要将health_check_type修改为ELB,否则,当您的Web应用程序进程崩溃,但您的EC2却保持健康时,该节点将不会被替换。

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

这是我使用的格式

$ 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

我在.ebextension目录下添加了下面的配置

示例:

option_settings:
  AWSEBV2LoadBalancerTargetGroup.aws:elasticbeanstalk:environment:process:default:
    HealthCheckPath: /health