我正在尝试触发事件桥规则:
{
"detail": {
"stateMachineArn": ["arn:aws:states:eu-west-2:<account-num>:stateMachine:<target-name>"],
"status": ["SUCCEEDED"]
},
"detail-type": ["detail-type"],
"source": ["aws.states"]
}
我正在尝试使用我的步骤函数中的以下步骤将事件放入默认总线:
"SendEventToEventBridge": {
"Type": "Task",
"Resource": "arn:aws:states:::events:putEvents",
"Parameters": {
"Entries": [
{
"Source": "aws.states",
"DetailType": "detail-type",
"Detail.$": "$.event",
"EventBusName": "default"
}
]
},
"End": true
}
但是当我尝试使用源“aws.states”在我的步骤函数中上传此事件时,我不断收到 NotAuthorizedForSourceException。据我所知,这是因为只有 AWS 服务事件可以使用源“aws.”。我认为从步骤函数发送事件本身就可以满足这个条件,但事实似乎并非如此。我很难理解,如何使用所需的“aws.states”源将事件发送到总线以满足规则?
您遇到的错误 (NotAuthorizedForSourceException) 是由于 EventBridge 事件中的 Source 字段必须反映被授权在该命名空间下发布事件的实际服务。在您的情况下,当 AWS Step Functions 发出自己的事件(例如 ExecutionStarted 或 ExecutionSucceeded)时,aws.states 是为 AWS Step Functions 保留的,而不是为您通过 Step Function 发送的自定义事件保留的。
不要对自定义事件使用 aws.states,而是为源选择唯一的命名空间。例如,使用类似 my-application 或 custom.states:
"SendEventToEventBridge": {
"Type": "Task",
"Resource": "arn:aws:states:::events:putEvents",
"Parameters": {
"Entries": [
{
"Source": "custom.states",
"DetailType": "detail-type",
"Detail.$": "$.event",
"EventBusName": "default"
}
]
},
"End": true
}
更新了 EventBridge 规则
{
"detail": {
"stateMachineArn": ["arn:aws:states:eu-west-2:<account-num>:stateMachine:<target-name>"],
"status": ["SUCCEEDED"]
},
"detail-type": ["detail-type"],
"source": ["custom.states"]
}