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

如何发送source为aws.states的事件触发Event Bridge规则?

解决Event Bridge规则触发与Step Functions事件发送权限问题

你遇到的NotAuthorizedForSourceException确实是因为只有AWS官方服务本身生成的事件才能使用aws.前缀的source字段——Step Functions作为执行载体,你通过它调用events:putEvents发送的是自定义事件,不属于AWS原生的aws.states事件范畴,因此被权限拦截。以下是两种可行的解决办法:

方案1:修改规则与事件,使用自定义source字段

这是最直接的实现方式,无需依赖AWS原生事件:

  1. 调整Step Functions的putEvents参数,将Source改为自定义前缀(比如custom.aws.states或myapp.stepfunctions):
"SendEventToEventBridge": {
  "Type": "Task",
  "Resource": "arn:aws:states:::events:putEvents",
  "Parameters": {
    "Entries": [
      {
        "Source": "custom.aws.states",
        "DetailType": "detail-type",
        "Detail.$": "$.event",
        "EventBusName": "default"
      }
    ]
  },
  "End": true
}
  1. 同步更新Event Bridge规则的source条件,匹配自定义的source值:
{
  "detail": {
    "stateMachineArn": ["arn:aws:states:eu-west-2:<account-num>:stateMachine:<target-name>"],
    "status": ["SUCCEEDED"]
  },
  "detail-type": ["detail-type"],
  "source": ["custom.aws.states"]
}

方案2:触发AWS原生aws.states事件

如果必须依赖aws.states作为source,无需手动发送事件,直接利用Step Functions本身的状态变更事件:

  1. Step Functions默认会在状态机执行状态变更(比如变为SUCCEEDED)时,自动向Event Bridge发送原生aws.states事件,无需额外配置。
  2. 修改Event Bridge规则的detail-type为Step Functions原生事件类型,保留source: ["aws.states"]和对应的detail条件:
{
  "detail": {
    "stateMachineArn": ["arn:aws:states:eu-west-2:<account-num>:stateMachine:<target-name>"],
    "status": ["SUCCEEDED"]
  },
  "detail-type": ["Step Functions Execution Status Change"],
  "source": ["aws.states"]
}

这种方式下,你可以删除状态机中的SendEventToEventBridge任务,状态机执行完成后会自动触发符合规则的事件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 05:02:17