在 AWS Step Functions Catch 方法的下游步骤中使用输出变量
我正在尝试使用 API 网关和简单的 POST/DELETE 端点来实现 Saga 模式。我首先创建一所大学,然后创建一个引用第一个大学的地址,如果此步骤失败,我想删除该大学。我不知道如何将大学的 id 传递给创建地址的捕获,因此我可以使用大学的 DB id 调用大学的 DELETE 端点。这是我当前的流程:
{
"Comment": "Calling ECS service that calls another service",
"StartAt": "Create University",
"States": {
"Create University": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "POST",
"Path": "universities",
"Headers": {
"Content-Type": [
"application/json"
]
},
"RequestBody": {
"name.$": "$.name",
"country.$": "$.country"
},
"AuthType": "NO_AUTH"
},
"ResultSelector": {
"id.$": "$.ResponseBody.id"
},
"Next": "Create Address"
},
"Create Address": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "POST",
"Path.$": "States.Format('/universities/{}/address', $.id)",
"Headers": {
"Content-Type": [
"application/json"
]
},
"RequestBody": {
"address.$": "$$.Execution.Input.address"
},
"AuthType": "NO_AUTH"
},
"ResultPath": "$.id",
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Delete University"
}
],
"End": true
},
"Delete Address": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "DELETE",
"Path.$": "States.Format('/universities/{}/address', $.id)",
"Headers": {
"Content-Type": [
"application/json"
]
},
"AuthType": "NO_AUTH"
},
"Next": "Delete University"
},
"Delete University": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "DELETE",
"Path.$": "States.Format('/universities/{}', $.id)",
"Headers": {
"Content-Type": [
"application/json"
]
},
"AuthType": "NO_AUTH"
},
"End": true
}
}
}
我需要使用 Create University
步骤返回的 ID 进入 Delete University
步骤,以便我可以正确调用 DELETE 端点。有什么想法吗?
I'm trying to implement a Saga pattern using API Gateway and simple POST/DELETE endpoints. I first create a University, then an Address referencing the first, and if this step fails I want to delete the University. I don't know how to pass the id of the University to the catch of the Create Address, so I can invoke the DELETE endpoint of the University, using its DB id. Here's my current flow:
{
"Comment": "Calling ECS service that calls another service",
"StartAt": "Create University",
"States": {
"Create University": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "POST",
"Path": "universities",
"Headers": {
"Content-Type": [
"application/json"
]
},
"RequestBody": {
"name.quot;: "$.name",
"country.quot;: "$.country"
},
"AuthType": "NO_AUTH"
},
"ResultSelector": {
"id.quot;: "$.ResponseBody.id"
},
"Next": "Create Address"
},
"Create Address": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "POST",
"Path.quot;: "States.Format('/universities/{}/address', $.id)",
"Headers": {
"Content-Type": [
"application/json"
]
},
"RequestBody": {
"address.quot;: "$.Execution.Input.address"
},
"AuthType": "NO_AUTH"
},
"ResultPath": "$.id",
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Delete University"
}
],
"End": true
},
"Delete Address": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "DELETE",
"Path.quot;: "States.Format('/universities/{}/address', $.id)",
"Headers": {
"Content-Type": [
"application/json"
]
},
"AuthType": "NO_AUTH"
},
"Next": "Delete University"
},
"Delete University": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
"Method": "DELETE",
"Path.quot;: "States.Format('/universities/{}', $.id)",
"Headers": {
"Content-Type": [
"application/json"
]
},
"AuthType": "NO_AUTH"
},
"End": true
}
}
}
I need to enter the Delete University
step with the id that the Create University
step returned, so I can call the DELETE endpoint correctly. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)