我正在尝试将JSON字符串发布到API网关,然后让API网关将JSON发送到EC2服务器。
我的问题是我找不到有关如何实现此目标的Amazon的优质文档。
当我测试设置时,我得到了
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response><Errors><Error><Code>InvalidHttpRequest</Code><Message>The HTTP request is invalid. Reason: Unable to parse request</Message></Error></Errors><RequestID>1fa47f52-d75c-4ff8-8992-3eac11a79015</RequestID></Response>"
这对我来说意义不大。我认为这是API网关尝试将请求发送到EC2的问题,因此无法生成此错误。因此,也许我在API网关中错误地设置了EC2 AWS服务代理。这可能是因为我不知道现在应该将“ Action”设置为什么,而我却将其指向EC2实例,仅是因为我看不到放置该信息的任何其他地方。
我真的不应该那么难,我已经成功地完成了与Lambda的连接,并仔细阅读了所有文档,而我所能找到的是:http : //docs.aws.amazon.com/apigateway/latest/developerguide/ Getting-started-aws-proxy.html#getting-started-aws-proxy-add-resources
对于这种情况,这没有什么用。有任何想法吗?
我认为您混淆了AWS Service Proxy和HTTP Service代理。
API网关可以将API调用转发到不同类型的后端:
-lambda函数
-AWS服务(请参阅http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services- s3.html为例)
-在AWS或本地运行的现有API(您的用例)
定义API时,请确保定义POST动词并将Endpoint URL指向您的EC2实例URL
我刚刚使用http://gurujsonrpc.appspot.com/在线提供的JSON POST服务进行了测试,它可以按预期工作。
这是我的测试API的Swagger导出。
{
"swagger": "2.0",
"info": {
"version": "2016-04-11T20:46:13Z",
"title": "test"
},
"host": "c22wfjg4d7.execute-api.eu-west-1.amazonaws.com",
"basePath": "/prod",
"schemes": [
"https"
],
"paths": {
"/": {
"post": {
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "200 response",
"schema": {
"$ref": "#/definitions/Empty"
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200"
}
},
"uri": "http://gurujsonrpc.appspot.com/guru",
"httpMethod": "POST",
"type": "http"
}
}
}
},
"definitions": {
"Empty": {
"type": "object"
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句