相关疑难解决方法(0)

通过API网关在aws Lambda中获取json主体

我目前正在使用NodeJS通过AWS Api Gateway在AWS lambda上构建机器人,我遇到了POST请求和JSON数据的问题.我的api使用'使用Lambda代理集成',甚至当我测试代理发送内容类型的Application/json和一些json在体内时,例如{"foo":"bar"}我无法访问该对象而不先解析它

例如

  var json = JSON.parse(event.body);
  console.log(json.foo);
Run Code Online (Sandbox Code Playgroud)

现在我知道通过JSON.parse运行它似乎并不是什么大不了的事,但我已经看到了许多其他例子,根本不是这种情况.请看这里https://github.com/pinzler/fb-messenger-bot-aws-lambda/blob/master/index.js

我是否需要向API网关添加任何内容才能正确处理?'post method request'部分中的'request body'步骤具有针对请求主体的内容类型application/json设置.

据我所知,上面例子的自述文件似乎没有使用代理集成,所以我不确定我应该在这里做什么

aws-lambda aws-api-gateway

52
推荐指数
3
解决办法
6万
查看次数

HTTP请求主体未通过AWS API Gateway进入AWS Lambda函数

我有一个用Scala编写的非常基本的lambda函数,已部署到AWS Lambda。当我通过AWS Lambda控制台对其进行测试时,该功能可以正常工作。

这是功能,其中添加了一些其他日志记录以用于调试目的。

package com.spacecorpshandbook.ostium.lambda.handler

import java.util

import com.google.gson.Gson
import temp.{ApiGatewayProxyResponse, Appointment, CancelResponse}

/**
  * Amazon Lambda handler adapter for the Cancellation application
  */
class CancellationHandler {

  def cancelAppointment(appointment: Appointment): ApiGatewayProxyResponse = {

    System.out.println("++++ appointmentId is: " + appointment.getAppointmentId)

    val apiGatewayProxyResponse = new ApiGatewayProxyResponse
    val cancelResponse = new CancelResponse

    cancelResponse.setMessage("Cancelled appointment with id " + appointment.getAppointmentId)

    val gson: Gson = new Gson

    apiGatewayProxyResponse.setBody(gson.toJson(cancelResponse))

    apiGatewayProxyResponse.setStatusCode("200")

    val headerValues = new util.HashMap[String, String]

    headerValues put("Content-Type", "application/json")

    apiGatewayProxyResponse.setHeaders(headerValues)

    System.out.println("+++++ message before returning: " …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-lambda aws-api-gateway

2
推荐指数
1
解决办法
3124
查看次数