Can someone explain to me how the functions are in...
# http4k
i
Can someone explain to me how the functions are invoked in a serverless environment? I'm still stuck on the idea that all kotlin apps must have a main function called
fun main
and the application plugin in gradle uses the file name with that function in MANIFEST.MF. I can see in the generated project it is pointing application.mainClass at the file containing the AppLoader, ApiGateway function and Event Handler. For an AWS Lambda how does it know to call the AppLoader?
s
In AWS, the Lambda Java runtime controls the class loading and the handling of events (API Gateway requests, events from other services, direct function invocations, etc). Here's a recent example that may be helpful: a single http4k function deployed as a Lambda Function URL using Pulumi: The entry point is just a class extending http4k's adapter (which provides the handler method). The function deployment points to it so AWS can work its magic.
a
Basically, lambda treats your JAR like a library, not a runnable application. When you set up the lambda in AWS, you configure it with the fully qualified class name of a
LambdaHandler
, containing a
handleRequest
function with the specific signature outlined here. Http4k comes with its own implementation of the
LambdaHandler
, so following the instructions Ivan linked is good enough. So if you do this, the Lambda runtime will load your jar and reflectively construct the class you passed into the config. Then it will invoke the
handleRequest
function. No main function necessary. To better understand how Lambda works, I suggest you try making a simple "hello world" python or javascript function, which is trivial to make in comparison to Java, and can even be done in Lambda's online editor. From there, you can try making a "hello world" function in java. If you can do that, you might be in a better position to understand how http4k fits itself into the Lambda.
i
Excellent explanations! I figured it must be something along the lines of a library that is called but I really wasn't sure. Thanks for your help!
❤️ 1