【问题标题】:Inputing parameters into Cloudwatch Event Rule Input parameter in Cloudformation将参数输入 Cloudwatch 事件规则 在 Cloudformation 中输入参数
【发布时间】:2021-01-02 13:59:12
【问题描述】:

我正在创建一个 Cloudwatch 事件规则,该规则应该在 Step Function 进入失败或超时状态时触发 lambda。云观察事件规则将参数传递给 lambda,后者将发送自定义 SNS 电子邮件。我正在尝试将输入参数的值从我在 Cloudformation 模板中设置的参数传递到 Cloudwatch 事件规则。我无法让 Cloudformation 将参数值提取到 Cloudwatch 事件规则输入参数中。 CF 采用我在 JSON 中提供的文字值并将其放入 Cloudwatch 事件规则中。我正在使用带有 JSON 参数文件的 YAML 模板。下面贴出代码。

FailureEvent:
Type: AWS::Events::Rule
DependsOn:
  - StateMachine
Properties:
  Description: !Ref FailureRuleDescription
  Name: !Ref FailureRuleName
  EventPattern:
    detail-type:
      - "Step Functions Execution Status Change"
    detail:
      status:
        - "FAILED"
        - "TIMED_OUT"
      stateMachineArn: [!Ref StateMachine]
  Targets:
    - Arn:
        'Fn::Join': ["", ['arn:aws:lambda:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':function:', !Ref FailureLambda]]
      Id: !Ref FailureLambda
      Input: '{"failed_service": "!Ref StateMachineName","sns_arn": {"Fn::Join":[":",["arn: aws: sns",{"Ref": "AWS: : Region"},{"Ref": "AWS::AccountId"},{"Ref": "SNSTopic"}]]}}'

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-cloudwatch


    【解决方案1】:

    你可以使用Sub:

    Input: !Sub '{"failed_service": "${StateMachineName}","sns_arn": "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${SNSTopic}"}'
    

    【讨论】:

    • 这个解决方案非常适合我。我还应该提醒任何阅读本文的人,我发现您需要向 events.amazon.com 提供权限才能调用您的 lambda。我在我的 Cloudformation 中添加了另一部分以授予此权限。有关详细信息,请参阅此帖子:stackoverflow.com/questions/61217571/…
    猜你喜欢
    • 2018-08-28
    • 2021-03-17
    • 2020-07-27
    • 1970-01-01
    • 2020-07-13
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多