I created a lambda function based on Micronaut and Kotlin. It provides two controllers,
"/" for just saying Hello World and
"/somefunc" for doing stuff.
When I execute it via CLI, it works as expected
aws lambda invoke --function-name MYFUNC --cli-binary-format raw-in-base64-out --payload '{ "path": "/somefunc" }' response.json
When I call the tests on the lambda page https://eu-central-1.console.aws.amazon.com/lambda/home?region=eu-central-1#/functions/MYFUNC?tab=testing
, it works as expected
But when I call the public URL https://THEPUBLICURL.lambda-url.eu-central-1.on.aws/somefunc, it always gets the result of calling the "/" controller.
And when I call https://THEPUBLICURL.lambda-url.eu-central-1.on.aws/somefuncthatdoesnotexist, it also respondes with the reply of the "/" controller.
The function handler is set to io.micronaut.function.aws.proxy.MicronautLambdaHandler
What am I doing wrong when calling the public URL?
Edit: Here is the example code:
package com.example
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.runtime.Micronaut.*
fun main(args: Array<String>) {
run(*args)
}
@Controller
open class HomeController {
@Get
fun hello() = mapOf("message" to "Hello World")
@Get("/somefunc")
fun somefunc() = mapOf("message" to "Hello some world")
}
2
Answers
So I finally find out: It's simply seems not to be possible to append paths to the public URL. The solution is to use an API Gatweway for calling the Lambda
According to https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html the payload of the lambda includes a
rawPath
attribute, not apath
attribute.Therefore your lambda code should handle its routing based on that attribute. And your manual invocation should look like