Reference: AWS: Lambda

dependencies {
    
    implementation(platform("org.http4k:http4k-bom:6.36.0.0"))

    implementation("org.http4k:http4k-connect-amazon-lambda")
    implementation("org.http4k:http4k-connect-amazon-lambda-fake")
}

The Lambda connector provides the following Actions:

 *  InvokeFunction

Example usage

fun main() {
    val deployedLambda = FunctionName.of("http4kLambda")

    val fakeLambda = FakeLambda(
        FnLoader {
            FnHandler { e: ScheduledEvent, ctx: Context ->
                println(e.toString())
                e.toString()
            }
        }
    )

    // we can connect to the real service or the fake (drop in replacement)
    val http: HttpHandler = if (USE_REAL_CLIENT) JavaHttpClient() else fakeLambda

    // create a client
    val client = Lambda.Http(Region.of("us-east-1"), { AwsCredentials("accessKeyId", "secretKey") }, http.debug())

    // all operations return a Result monad of the API type
    val invokeResult: Result<Resp, RemoteFailure> = client.invokeFunction(
        deployedLambda,
        ScheduledEvent().apply {
            account = "awsAccount"
        }, Moshi
    )
    println(invokeResult)
}

Note that the http4k-connect Fake Lambda implementation is designed to provide a runtime environment for function HttpHandlers that will be invoked directly using the Lambda URL pattern (https://lambda.${scope.region}.amazonaws.com/2015-03-31/functions/$name/invocations), rather than being deployed behind APIGateway (where you have total control over the URL pattern where the lambda can be invoked).

The client APIs utilise the http4k-platform-aws module for request signing, which means no dependencies on the incredibly fat Amazon-SDK JARs. This means this integration is perfect for running Serverless Lambdas where binary size is a performance factor.

Default Fake port: 50322

To start:

FakeLambda("INSERT FnLoader").start()
scarf