Limey
Limey

Reputation: 2770

Scala: Get URL Parameters

I'm writing my first Scala lambda, and I have run into a bit of an issue, which i think should be straightforward, but I'm having trouble finding the answer.

So I have the following code that will allow me to accept json and use it in the lambda.

--eventTest.scala
 val stream : InputStream = getClass.getResourceAsStream("/test_data/body.json")

--request handler
def handleRequest(input: InputStream): Unit = {
   val name = scalaMapper.readValue(input, classOf[NameInfo])
   val result = s"Hello there,  ${name.firstName} ${name.lastName}."
   println(result)
}

This works just fine, but I'm having problems figuring out how to be able to get URL parameters. Does it automatically use the same input Stream? There is seems to be very little documentation on this in Scala.

Thanks

Upvotes: 0

Views: 187

Answers (1)

Parsifal
Parsifal

Reputation: 4516

A Lambda function's event is a JSON object. The Lambda runtime will introspect the handler function and attempt to extract or convert that object based on the function signature. I believe the easiest representation is a java.util.Map[String,String] (iirc, Lambda doesn't have a Scala runtime, so you'll have to use Java classes and convert them).

An example event from the API Gateway proxy integration: https://github.com/awsdocs/aws-lambda-developer-guide/blob/master/sample-apps/nodejs-apig/event.json

For more information about the Java runtime: https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html

Upvotes: 1

Related Questions