aws-lambda-scala
- just finished beating my head against the wall with a node.js lambda ,if I'm reading the code correctly, you have to setup the lambda handler as either a native lambda request handle or an API gateway handler, it doesn't handle both in a single API?
case class ShoppingItem(orderDate: String, item: String)
object ApiGatewayScalaHandler {
case class Req(item: String)
case class Resp(message: ShoppingItem, request: Req)
}
class ApiGatewayScalaHandler extends Proxy[Req, Resp] {
val logger: Logger = LogManager.getLogger(getClass)
override def handle(input: proxy.ProxyRequest[Req], c: Context): Either[Throwable, ProxyResponse[Resp]] = {
logger.info(s"Received a request: $input")
val headers = Map("x-custom-response-header" -> "my custom response header value")
val responseBodyOption = input.body.map(req => Resp(ShoppingItem(DateTime.now().toString(),req.item), req))
Right(ProxyResponse(200, Some(headers), responseBodyOption))
}
package:
artifact: target/scala-2.13/hello.jar
functions:
hello:
handler: hello.ApiGatewayScalaHandler::handle
events:
- http:
path: serverless-dev-hello-API
method: post
async: true
When I run it asynchronously by keeping the API gateway Integration Request type to non-proxy LAMBDA with added header X-Amz-Invocation-Type set to 'Event', I get the following content mapped to my destination Email ( I have set Email destination when lambda invokes aync and on success)
{"version":"1.0","timestamp":"2019-12-20T12:11:44.580Z","requestContext":{"requestId":"a4299c1b-3837-4eec-a539-d6534a237037","functionArn":"arn:aws:lambda:ap-south-1:XXXXXXXXXXX:function:serverless-dev-hello:$LATEST","condition":"Success","approximateInvokeCount":1},"requestPayload":{"item":"banana"},"responseContext":{"statusCode":200,"executedVersion":"$LATEST"},"responsePayload":{"statusCode":500,"headers":{"Content-Type":"text/plain; charset=UTF-8"},"body":"Attempt to decode value on failed cursor: DownField(path)"}}
Why do I not get the response payload same as before?
Proxy[Req, Resp]
won’t work for non-proxy LAMBDA integration.