Hi... super impressed with how quickly you guys ar...
# http4k
a
Hi... super impressed with how quickly you guys are able to add new integrations. Trying out the AWS Lambda by converting a working API. 2 questions... can it be run locally? There is no
main()
when the entry point is
class HelloServerlessHttp4k : ApiGatewayV1LambdaFunction(http4kApp)
. Also, how to import the
LambdaHttpClient
? thank you
s
We assume that because you have an
HttpHandler
you can simply create a
main
with
http4App.asServer(...).start()
. Would that be enough or do you need lambda-specific things running locally?
The
LambdaHttpClient
was intended to our internal integration tests, mainly, that's why it's in the
test
source directory. What's your use case for it? We could move it (although I'd probably consider a new module
http4k-client-lambda
to keep the
http4k-serverless-lambda
small)
d
As @s4nchez says - there should be no reason to directly invoke the Lambdas as you can just mount the HttpHandler directly into a server. For invoking "direct" lambdas directly inside AWS, you can use the Lambda client in http4k-connect, although this doesn't do the API gateway translation for REST or HTTP gateway types (which is provided by the various adapter function classes). You may want to model your app construction as an AppLoader and then use the environment to construct the HttpHandler if that is simpler for "booting".
a
do you guys ever sleep ? 🙂 yes I started with a
http4App.asServer(...).start()
. Works fine on a basic server. But if I convert to Lambda, the API Gateway sends its own custom JSON payload (https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html). My understanding was the
ApiGatewayV2LambdaFunction
converts that payload back into a "normal" request that http4k can handle with a normal route.
d
Yes - but I'm a bit confused about when you actually need to call that directly. The point of the adapters is that for local testing, you can just use the HttpHandler directly, then when calling it though the ApiGateway you just use the handler which is plugged into the adapter.
a
I see what you are saying... just that when I take my working API, change to use the adapter then upload to Lambda, I get all kinds of errors. I can't see the payload that the API Gateway is actually sending to my code so can't really debug or identify the problem, all I can do is guess and re-upload a new JAR to Lambda and try again.
d
Ah - then it sounds like you're maybe using the wrong adapter? There are 3 options depending on the style of.api gateway that you're using.
a
Hey there... thank you for your help. What was happening is that another component of my app was throwing errors upon startup because it was not properly configured to run on AWS Lambda. Once I fixed that and managed to configure the API Gateway service, http4k worked great. Exactly what you stated, on my dev machine I do a
myRoutes.asServer(Undertow(8080)).start()
inside a main() method, while on Lambda I use a class defined with
ApiGatewayV2LambdaFunction(myRoutes)
and that's all I needed to accept and respond to HTTP requests. Very cool! (and that's what I get for moving a complex app on my first try instead of a hello-world)