Hi. How can I use the `DynamoDbEvent` with `AwsLam...
# http4k
a
Hi. How can I use the
DynamoDbEvent
with
AwsLambdaEventFunction
? Here is what I've got currently simplified:
Copy code
class DynamoDbLambdaAdapter : AwsLambdaEventFunction(FnLoader { env: Env ->
    FnHandler { event: DynamoDbEvent, _: Context ->
        event
    }
})
This code won't work because it does not match the AWS request, as the Http4k one uses Values4k. I do have a working version of the AwsLambdaEventFunction, but it uses AWS models. Eliminating the AWS dependency would be nice, as I use Http4k in it anyway.
If you click through, we are using the AwsLambdaMoshi to do the automarshalling of the event
assuming you're using: com.amazonaws.services.lambda.runtime.events;.DynamoDbEvent
a
yes just lowercase db
DynamodbEvent
d
yep - that looks familiar
a
it fails for me when it gets to awsRegion, because it expects a string but i finds object
which is an Values4k Region
d
? values4k isn't involved in this . you're attempting to deserialise into the amazon type aren't you?
a
the amazon type works as expected
d
ah - then you will need to use the DynamoDbMoshi instead
a
here is the example test:
Copy code
class DynamoAdapterTest {
    private val mockContext = mockk<Context>()
    private val logger = TestLogger
    private val json = AwsLambdaMoshi

    private fun sut(returns: Either<UseCaseError, Unit>) =
        object : DynamoDbLambdaAdapter2({ returns }) {}

    @Test
    fun `valid request returns empty batch response`() {
        val input = ByteArrayInputStream(validDynamoDBEventStream.toByteArray())
        val output = ByteArrayOutputStream()

        sut(Unit.right()).handleRequest(input, output, mockContext)

        val response = json.asA<StreamsEventResponse>(output.toString())
        response shouldBe emptyBatchResponse
    }
}
d
so you will need to replace the moshi used:
Copy code
fun EventFnLoader(http: HttpHandler) = FnLoader(DynamoDbMoshi) { env: Map<String, String> ->
    loggingFunction.then(EventFnHandler(http))
}
that will give you the http4k type and you can remove the aws jar
👀 1
a
That does the trick. I see the difference now between the two.
d
amazing 🙂
a
Thanks David! And see you later 😉
which is my return type
it is the same as SQSBatchResponse, but it is not part of
org.http4k.connect.amazon.dynamodb.events
d
nope. Feel free to PR it in though. 🙂
👍 1
a