我们可以在 API 网关中使用 GET 方法来调用步骤函数吗?

huangapple go评论54阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月16日 18:41:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471090.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定