AWS API网关和EC2服务代理

wmf*_*cia 9 amazon-ec2 amazon-web-services aws-api-gateway

我正在尝试将json字符串发布到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>"
Run Code Online (Sandbox Code Playgroud)

这对我来说意义不大.我认为这是一个问题,API网关试图将请求发送到EC2,它不能生成此错误.因此,我可能错误地在API网关中设置了EC2 AWS服务代理.这可能是因为我不知道我应该将'Action'设置为现在我指向EC2实例,只是因为我没有看到任何其他地方放置该信息.

这真的不应该那么难,我已经成功完成了连接到Lambda的这个东西,并查看了所有文档,我可以找到的是:http://docs.aws.amazon.com/apigateway/latest/developerguide/越来越开工-AWS-proxy.html#工具入门-AWS代理加资源

这对于这种情况不太有帮助.有任何想法吗?

Séb*_*acq 14

我认为您混淆了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谓词并将端点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"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)