Can't invoke function via URL

Viewed 40

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")

}
1 Answers

According to https://docs.aws.amazon.com/lambda/latest/dg/urls-invocation.html the payload of the lambda includes a rawPath attribute, not a path attribute.

Therefore your lambda code should handle its routing based on that attribute. And your manual invocation should look like

aws lambda invoke --function-name MYFUNC --cli-binary-format raw-in-base64-out --payload '{ "rawPath": "/somefunc" }' response.json
Related