我在CloudFormation模板中描述了我的AWS资源,并面临下一个问题-我已通过HTTPS协议订阅了SNS。使用该订阅,我通过API Gateway链接了CloudWatch警报的SNS主题,该主题将这些警报转发到Slack webhook。在我的CloudFormation模板中,我已经描述了API网关元素(REST API,资源和方法):
Resources:
AlarmRestApi:
Type: "AWS::ApiGateway::RestApi"
Properties:
Name: "sns-to-slack"
Description: "REST API for forwarding CloudWatch alarms to Slack"
SlackAlarmsResource:
Type: "AWS::ApiGateway::Resource"
Properties:
RestApiId: !Ref "AlarmRestApi"
ParentId: !GetAtt "AlarmRestApi.RootResourceId"
PathPart: "slack-alarms"
AlarmRestApiStage:
Type: "AWS::ApiGateway::Stage"
Properties:
DeploymentId: !Ref "RestApiDeployment"
RestApiId: !Ref "AlarmRestApi"
StageName: "dev"
...
当前,我描述了SNS主题和订阅,但无法获取'SlackAlarmsResource'的PathPart属性,以避免在订阅模板中对其进行硬编码。具有硬编码的资源值,看起来:
CloudWatchAlarmsTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: "cloudwatch-alarms"
TopicName: "cloudwatch-alarms"
CloudWatchAlarmsSubcscription:
Type: "AWS::SNS::Subscription"
Properties:
TopicArn: !Ref "CloudWatchAlarmsTopic"
Endpoint: !Sub "https://${AlarmRestApi}.execute-api.${AWS::Region}.amazonaws.com/${AlarmRestApiStage}/slack-alarms"
Protocol: https
RawMessageDelivery: true
如何在SNS订阅终结点属性中获取API网关资源的PathPart值(“松弛警报”)?