当源状态机出现故障时,Cloudwatch 事件规则不会调用

Cloudwatch Event Rule doesn't invoke when source state machine fails

我有一个阶梯函数,运行有 2 个独立的 lambda。如果步骤功能失败或超时,我想通过 SNS 收到一封电子邮件,告诉我步骤功能失败。我使用 cloudformation 创建了事件规则,并在事件模式中指定了状态机 ARN。当步骤功能失败时,不会发送任何电子邮件。如果我删除 stateMachineArn 参数和 运行 我的步骤函数,我会收到失败电子邮件。我已经多次检查我是否为状态机输入了正确的 ARN。事件规则的 CF 如下(YAML 格式)。谢谢

  FailureEvent:
    Type: AWS::Events::Rule
    DependsOn:
      - StateMachine
    Properties:
      Name: !Ref FailureRuleName
      Description: "EventRule"
      EventPattern:
        detail-type:
          - "Step Functions Execution Status Change"
        detail:
          status:
            - "FAILED"
            - "TIMED_OUT"
        stateMachineArn: ["arn:aws:states:region:account#:stateMachine:statemachine"]
      Targets:
        -
          Arn:
            Ref: SNSARN
          Id: !Ref SNSTopic

我确实修复了这个问题并对其进行了扩展,以调用使用 lambda 发布自定义 SNS 电子邮件的 lambda。我的对齐方式在我的 EventPattern 部分中关闭。见下文。感谢@Marcin。

FailureEvent:
Type: AWS::Events::Rule
DependsOn:
  - FMIStateMachine
Properties:
  Description: !Ref FailureRuleDescription
  Name: !Ref FailureRuleName
  State: "ENABLED"
  RoleArn:
    'Fn::Join': ["", ['arn:aws:iam::', !Ref 'AWS::AccountId', ':role/', !Ref LambdaExecutionRole]]
  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: !Sub '{"failed_service": "${StateMachineName}","sns_arn": "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${SNSTopic}"}'