英文:
Can we use GET method in api-gateway to invoke step function?
问题
我正在从 API 网关调用步骤函数。对于 POST 请求,它可以正常工作。我可以使用 GET 请求吗?因为我们必须在请求体或映射模板中传递状态机 ARN。是否有任何解决方法?
以下是我的云形成模板:
"paths": {
"/individual": {
"get": {
"operationId": "GET HTTP",
"responses": {
"200": {
"description": "200 响应"
}
},
"x-amazon-apigateway-integration": {
"type": "AWS",
"httpMethod": "GET",
"uri": "arn:aws:apigateway:eu-west-1:states:action/StartExecution",
"credentials": {
"Fn::GetAtt": [
"apiGatewayIamRoleGet",
"Arn"
]
},
"requestTemplates": {
"application/json": {
"Fn::Sub": [
"#set($body= $input.json('$'))\n #set($inputRoot='{ \"inputData\" :'+$body+',\"apiInfo\":{\"httpMethod\" :\"'+ $context.httpMethod+'\",\"apiKey\" :\"'+ $context.identity.apiKey+'\"}}')\n #set($apiData=$util.escapeJavaScript($inputRoot))\n #set($apiData=$apiData.replaceAll(\"\\'\",\"'\"))\n {\n \"input\" :\"$apiData\",\n \"stateMachineArn\": \"${StepFunctionArn}\" \n }",
{
"StepFunctionArn": {
"Ref": "StepFunctionGet"
}
}
]
}
},
"payloadFormatVersion": 1.0,
"responses": {
"default": {
"statusCode": "200"
}
}
}
}
}
}
英文:
I am invoking step function from api-gateway. For POST request it is working fine. Can I use GET request as well? as we we have to pass state-machine ARN in body or mapping template. Is there any work around?
Below is my cloud formation template:
"paths": {
"/individual": {
"get": {
"operationId": "GET HTTP",
"responses": {
"200": {
"description": "200 response"
}
},
"x-amazon-apigateway-integration": {
"type": "AWS",
"httpMethod": "GET",
"uri": "arn:aws:apigateway:eu-west-1:states:action/StartExecution",
"credentials": {
"Fn::GetAtt": [
"apiGatewayIamRoleGet",
"Arn"
]
},
"requestTemplates": {
"application/json": {
"Fn::Sub": [
"#set($body= $input.json('$'))\n #set($inputRoot='{ \"inputData\" :'+$body+',\"apiInfo\":{\"httpMethod\" :\"'+ $context.httpMethod+'\",\"apiKey\" :\"'+ $context.identity.apiKey+'\"}}')\n #set($apiData=$util.escapeJavaScript($inputRoot))\n #set($apiData=$apiData.replaceAll(\"\\'\",\"'\"))\n {\n \"input\" :\"$apiData\",\n \"stateMachineArn\": \"${StepFunctionArn}\" \n }",
{
"StepFunctionArn": {
"Ref": "StepFunctionGet"
}
}
]
}
},
"payloadFormatVersion": 1.0,
"responses": {
"default": {
"statusCode": "200"
}
}
}
}
}
}
答案1
得分: 0
我已解决了这个问题。api-gateway集成中的httpMethod需要是POST,我之前使用了GET,导致出现错误。
英文:
I have sorted out the issue. httpMethod in api-gateway integration needs to be POST I used GET there which causing error.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论