Aws api gateway Github Webhook到AWS API网关与SQS Bug集成?

Aws api gateway Github Webhook到AWS API网关与SQS Bug集成?,aws-api-gateway,amazon-sqs,github-webhook,Aws Api Gateway,Amazon Sqs,Github Webhook,我的这个基本上是有效的。Github发送的所有事件都会在我的SQS队列中结束。webhook在组织级别发送带有“Send me Everything”的application/json。我正在API网关中使用以下模板映射: Action=SendMessage&MessageBody={ "bodyJson":"$util.base64Encode($util.json('$'))", "requestId":"$context.requestId", "resourcePa

我的这个基本上是有效的。Github发送的所有事件都会在我的SQS队列中结束。webhook在组织级别发送带有“Send me Everything”的application/json。我正在API网关中使用以下模板映射:

Action=SendMessage&MessageBody={
  "bodyJson":"$util.base64Encode($util.json('$'))",
  "requestId":"$context.requestId",
  "resourcePath":"$context.resourcePath",
  "apiId":"$context.apiId",
  "stage":"$context.stage",
  "resourceId":"$context.resourceId",
  "path":"$context.path",
  "protocol":"$context.protocol",
  "requestTimeEpoch":"$context.requestTimeEpoch",
  "X-GitHub-Event":"$method.request.header.X-GitHub-Event",
  "X-GitHub-Delivery":"$method.request.header.X-GitHub-Delivery",
  "X-Hub-Signature":"$method.request.header.X-Hub-Signature"
}
(我还尝试了“bodyJson”:“$util.base64Encode($util.body)”,”

来自Github的大约5%的事件通知(各种事件类型,例如:状态、推送)无法正确转换。当我从队列转到base64解码消息时,我得到部分消息/部分随机垃圾。您已经注意到,每次重试时重新发送同一事件都会失败。(不过该事件在Github UI中看起来像格式良好的json。)我正在登录到cloudwatch,但日志被截断。所以我不知道有多少原始信息通过。我还尝试将application/json设置为二进制媒体类型。这导致所有事件在转换时失败,并返回500到Github。有人知道我做错了什么,或者这是一个bug吗

更新 需要再测试一点,但我想我已经知道了。我们需要对base64编码的bodyJson进行url编码,因为base64编码输出包含的字符(+和/)在没有url编码的情况下与application/x-www-form-urlencoded不兼容:

            Action=SendMessage&MessageBody={
              "bodyJson":"$util.urlEncode($util.base64Encode($input.body))",
              "requestId":"$context.requestId",
              "resourcePath":"$context.resourcePath",
              "apiId":"$context.apiId",
              "stage":"$context.stage",
              "resourceId":"$context.resourceId",
              "path":"$context.path",
              "protocol":"$context.protocol",
              "requestTimeEpoch":"$context.requestTimeEpoch",
              "X-GitHub-Event":"$method.request.header.X-GitHub-Event",
              "X-GitHub-Delivery":"$method.request.header.X-GitHub-Delivery",
              "X-Hub-Signature":"$method.request.header.X-Hub-Signature"
            }