compile group: "org.http4k", name: "http4k-serverless-lambda", version: "3.21.1"
These modules provide integration with Serverless deployment environments, such as AWS Lambda.
AWS Lambda integration
Since http4k is server independent, it turns out to be fairly trivial to deploy full applications to AWS Lambda, and then call them by setting up the API Gateway to proxy requests to the function. Effectively, the combination of these two services become just another Server back-end supported by the library. This has the added bonus that you can test your applications in a local environment and then simply deploy them to AWS Lambda via S3 upload.
In order to achieve this, only a single interface
AppLoader needs to be implemented.
This is far from a complete guide, but configuring AWS Lambda and the API Gateway involves several stages:
- Users, Roles and Policies for the API Gateway and Lambda.
- API Gateway to proxy all requests to your Lambda.
- Building your http4k application into a standard UberJar.
- Optionally using Proguard to minify the JAR.
- Package up the (minified) JAR into a standard Zip distribution.
Create and configure the Lambda function, and at the same time:
- Upload the standard Zip file to S3.
- Set the function execution to call the main http4k entry point:
- Set an environment variable for the Lambda
HTTP4K_BOOTSTRAP_CLASSto the class of your
We hope to soon provide some tools to automate at least some of the above process, or at least document it somewhat. However, AWS is a complicated beast and many people have a preferred way to set it up: CloudFormation templates, Serverless framework, Terraform, etc. In the meantime, here is an example of how the
AppLoader is created and a sneak peak at launching the app locally: