Amazon web services 将参数输入Cloudwatch事件规则Cloudformation中的输入参数

Amazon web services 将参数输入Cloudwatch事件规则Cloudformation中的输入参数,amazon-web-services,amazon-cloudformation,amazon-cloudwatch,Amazon Web Services,Amazon Cloudformation,Amazon Cloudwatch,我正在创建一个Cloudwatch事件规则,如果Step函数进入失败或超时状态,它应该触发lambda。云监视事件规则将参数传递给lambda,lambda将发送一封自定义SNS电子邮件。我试图将输入参数的值从我在Cloudformation模板中设置的参数传递到Cloudwatch事件规则中。我无法让Cloudformation将参数值提取出来,并将它们放入Cloudwatch事件规则输入参数。CF接受我在JSON中给出的文本值,并将其放入Cloudwatch事件规则中。我正在使用带有JSON

我正在创建一个Cloudwatch事件规则,如果Step函数进入失败或超时状态,它应该触发lambda。云监视事件规则将参数传递给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"}]]}}'
您可以使用:


这个解决方案对我非常有效。我还应该提醒阅读本文的任何人,我发现您需要向events.amazon.com提供调用lambda的权限。我在我的Cloudformation中添加了另一块,以获得此许可。有关更多详细信息,请参阅本文:。
Input: !Sub '{"failed_service": "${StateMachineName}","sns_arn": "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${SNSTopic}"}'