You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在us-east-1为us-west-2的AWS Route53健康检查配置CloudFormation告警问题

解决方案:跨区域CloudWatch告警引用Route53健康检查ID

问题核心是CloudFormation堆栈无法跨区域直接引用其他区域堆栈的资源属性,每个堆栈的资源仅在所属区域内可见。要在us-east-1的告警中关联us-west-2的Route53健康检查,可按以下步骤处理:

步骤1:在us-west-2的堆栈中输出健康检查ID

在部署Route53健康检查的us-west-2 CloudFormation模板里,添加Outputs段暴露HealthCheckId:

Outputs:
  Route53HealthCheckId:
    Value: !GetAtt HealthCheckWithEndpoint.HealthCheckId
    Export:
      Name: !Sub "${AWS::StackName}-HealthCheckId"

步骤2:将健康检查ID传递给us-east-1的堆栈

有两种可靠方式传递这个ID:

  • 手动传递:从us-west-2堆栈的输出中复制HealthCheckId,作为参数传入us-east-1的堆栈。
  • CLI批量传递:通过AWS CLI先获取导出值,再创建us-east-1堆栈时作为参数传入:
# 获取us-west-2堆栈的健康检查ID
HEALTH_CHECK_ID=$(aws cloudformation describe-stacks --stack-name YOUR-WEST-STACK-NAME --region us-west-2 --query "Stacks[0].Outputs[?OutputKey=='Route53HealthCheckId'].OutputValue" --output text)

# 在us-east-1创建堆栈,传入参数
aws cloudformation create-stack --stack-name YOUR-EAST-STACK-NAME --template-body file://east-template.yaml --parameters ParameterKey=HealthCheckIdParam,ParameterValue=$HEALTH_CHECK_ID --region us-east-1

步骤3:修改us-east-1的告警模板

将原来通过!GetAtt引用同堆栈资源的方式,改为引用传入的参数:

Parameters:
  HealthCheckIdParam:
    Type: String
    Description: 来自us-west-2区域的Route53健康检查ID
  AlarmTopic:
    Type: String
    Description: 告警通知SNS主题ARN

Conditions:
  IsEast1AndMultiRegion:
    # 保留原有条件定义
    ...

Alarm:
  Condition: IsEast1AndMultiRegion
  Type: AWS::CloudWatch::Alarm
  Properties:
    ActionsEnabled: true
    AlarmActions:
      - !Ref AlarmTopic
    ComparisonOperator: LessThanOrEqualToThreshold
    EvaluationPeriods: 1
    MetricName: HealthCheckPercentageHealthy
    Namespace: AWS/Route53
    AlarmDescription: "告警:Route53健康检查异常"
    Period: 60
    Statistic: Maximum
    Threshold: 99
    TreatMissingData: notBreaching
    Dimensions:
      - Name: HealthCheckId
        Value: !Ref HealthCheckIdParam  # 替换为传入的跨区域参数
      - Name: Region
        Value: us-west-2  # 明确指定被监控的资源所在区域

关键说明

  • Route53健康检查是全局资源,但CloudWatch的AWS/Route53指标会按区域维度区分,必须在Dimensions里指定Region: us-west-2才能正确关联目标健康检查的指标。
  • 跨区域堆栈间的资源引用无法通过CloudFormation原生的!GetAtt或!Ref实现,必须通过输出+参数传递的方式完成。

内容的提问来源于stack exchange,提问作者elena

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 22:20:29