AWS API网关和EC2服务代理



我正在尝试将json字符串POST到API网关,然后让API网关将json发送到EC2服务器。

我的问题是,我找不到亚马逊关于如何做到这一点的好文档。

当我测试设置时,我得到了这个

"<?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-已启动aws代理添加资源

这对这种情况没有多大帮助。有什么想法吗?

我认为您混淆了AWS服务代理和HTTP服务代理。

API网关可以将API调用转发到不同类型的后端:
-lambda函数
-AWS服务(请参阅http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html例如)
-现有API,运行在AWS或内部部署(您的用例)上

定义API时,请务必定义POST谓词,并将EndpointURL指向EC2实例URL

我刚刚使用在线的JSONPOST服务做了一个测试http://gurujsonrpc.appspot.com/并且它如预期的那样工作。

这是我的测试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"
    }
  }
}

最新更新