amazon-web-services - 未找到 stepfunction 时将状态码从 200 更改为 404
问题描述
我正在尝试从 API Gateway 执行 AWS step 功能,它按预期工作。
每当我传递输入时, statemachinearn(stepfunction name to execute) 它都会触发 step 函数。
但是它仍然返回状态码 200,每当它无法找到 stepfunction 时,如果 apigateway 没有找到该 stepfunction,我想返回状态码 404。
你能帮我吗?
回复:
状态:200ok
预期的:
状态:404
谢谢,
哈里卡。
解决方案
根据文档StartExecution API 调用确实返回400 Bad Request
不存在的状态机,这是正确的RESTful API
标准。
状态机不存在
指定的状态机不存在。
HTTP 状态码:400
从 RESTful API 的角度来看,端点/execution/
(我在 API Gateway 中为集成设置创建)是一种资源,无论它接受 GET 或 POST 还是其他东西。404 仅适用于资源/execution/
本身不存在的情况。如果/execution/
端点存在,但它的调用失败(无论什么原因)response status code must be something other than 404
,.
POST
因此,在使用状态机调用返回的响应(200)的情况下,non-existent
它是正确的。但是,当API Gateway
尝试调用non-existent
statemachine 时,它404
从StartExecution
api 调用中获得,它最终包装成正确的消息,而不是返回404
http 响应。
curl -s -X POST -d '{"input": "{}","name": "MyExecution17","stateMachineArn": "arn:aws:states:eu-central-1:1234567890:stateMachine:mystatemachine"}' https://123456asdasdas.execute-api.eu-central-1.amazonaws.com/v1/execution|jq .
{
"__type": "com.amazonaws.swf.service.v2.model#StateMachineDoesNotExist",
"message": "State Machine Does Not Exist: 'arn:aws:states:eu-central-1:1234567890:stateMachine:mystatemachine1'"
}
假设您创建了另一个,您可以在其中提供您想要返回MethodResponse
的确切信息,并且您必须通过提供OR a来选择。HTTP Status Code
404
Integration Response
Method Response
Exact HTTP Responce Code(400 -> Upstream response from the **StartExecution** API Call)
Regex -> (4\{d}2) matching all the 4xx errors
在这种情况下,您将为404
上游错误4xx
StartExecution Errors的所有响应提供
- ExecutionAlreadyExists -> 400
- ExecutionLimitExceeded -> 400
- InvalidArn -> 400
- 无效的执行输入-> 400
- 无效名称 -> 400
- 状态机删除 -> 400
- StateMachineDoesNotExist -> 400
不存在的状态机:
curl -s -X POST -d '{"input": "{}","name": "MyExecution17","stateMachineArn": "arn:aws:states:eu-central-1:1234567890:stateMachine:mystatemachine1"}' https://123456asdasdas.execute-api.eu-central-1.amazonaws.com/v1/execution|jq .
< HTTP/2 404
< date: Sat, 30 Jan 2021 14:12:16 GMT
< content-type: application/json
...
{
"__type": "com.amazonaws.swf.service.v2.model#StateMachineDoesNotExist",
"message": "State Machine Does Not Exist: 'arn:aws:states:eu-central-1:1234567890:stateMachine:mystatemachine1'"
}
执行已经存在
curl -s -X POST -d '{"input": "{}","name": "MyExecution17","stateMachineArn": "arn:aws:states:eu-central-1:1234567890:stateMachine:mystatemachine"}' https://123456asdasdas.execute-api.eu-central-1.amazonaws.com/v1/execution|jq .
* We are completely uploaded and fine
< HTTP/2 404
< date: Sat, 30 Jan 2021 14:28:27 GMT
< content-type: application/json
{
"__type": "com.amazonaws.swf.service.v2.model#ExecutionAlreadyExists",
"message": "Execution Already Exists: 'arn:aws:states:eu-central-1:1234567890:execution:mystatemachine:MyExecution17'"
}
我认为这会产生误导。
推荐阅读
- c# - 通过 nuget.exe 获取所有已安装的 nuget 依赖项
- java - 使用 Tomcat 8 将外部日志配置的位置指定到特定的 webapps
- mysql - MariaDB 未启动:“插件 'FEEDBACK' 已禁用。”
- c# - 架构层图验证在 .Net 核心中不起作用
- r - 图节点之间的乘法距离
- c# - ClosedXml :在带有空格的表中设置列的名称
- nightwatch.js - 如何通过 Nightwatch.js 从窗口中获取方法?
- c# - Selenium 与 Sikuli4Net 无法将图像与从 chrome 驱动程序启动的全屏进行比较
- javascript - Google Apps 脚本 - 电子邮件作为字符串
- salesforce - 使用 External_ID__c 不会在 Salesforce 的联系人中加载任何记录