根据文档StartExecution API 调用,对于不存在的状态机返回400 Bad Request,这与RESTful API 标准是正确的。
StateMachineDoesNotExist
指定的状态机不存在。
HTTP 状态码:400
从 RESTful API 的角度来看,端点 /execution/(我在 API Gateway 中为集成设置创建)是一种资源,无论它接受 GET 或 POST 或其他什么。 404 仅适用于资源 /execution/ 本身不存在时。如果/execution/ 端点存在,但调用失败(无论什么原因),response status code must be something other than 404。
因此,对于使用non-existent 状态机的POST 调用返回的响应(200)是正确的。但是当API Gateway 尝试调用non-existent 状态机时,它从StartExecution api 调用中得到404,它最终包装成正确的消息而不是返回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,您可以在其中提供您想要返回的确切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。
在这种情况下,您将为上游错误4xx StartExecution Errors 的所有响应提供404
- ExecutionAlreadyExists -> 400
- ExecutionLimitExceeded -> 400
- InvalidArn -> 400
- InvalidExecutionInput -> 400
- 无效名称 -> 400
- StateMachineDeleting -> 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'"
}
我认为这会产生误导。