JetBrains / kotless

Kotlin Serverless Framework
Apache License 2.0
1.15k stars 57 forks source link

[BUG] Scheduled Event Lambda Handler #50

Open gary-lo opened 4 years ago

gary-lo commented 4 years ago

Currently in https://github.com/JetBrains/kotless/blob/master/dsl/kotless/lang/src/main/kotlin/io/kotless/dsl/LambdaHandler.kt#L43 it uses a raw JSON String check to determine the type of CloudWatch Event. However for example if I created a POST request with body

{
    "Scheduled Event": "Scheduled Event"
}

This will try to deserialize as CW event

val event = Json.parse(CloudWatch.serializer(), jsonRequest)

And then throw

2020-08-18 12:45:37.138 ERROR LambdaHandler:57 - Error occurred during handle of request and was not caught
kotlinx.serialization.MissingFieldException: Field 'source' is required, but it was missing
    at io.kotless.dsl.model.CloudWatch.<init>(CloudWatch.kt)
    at io.kotless.dsl.model.CloudWatch$$serializer.deserialize(CloudWatch.kt)
    at io.kotless.dsl.model.CloudWatch$$serializer.deserialize(CloudWatch.kt:7)
    at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:34)
    at kotlinx.serialization.json.internal.StreamingJsonInput.decodeSerializableValue(StreamingJsonInput.kt:33)
    at kotlinx.serialization.CoreKt.decode(Core.kt:80)
    at kotlinx.serialization.json.Json.parse(Json.kt:126)
    at io.kotless.dsl.LambdaHandler.handleRequest(LambdaHandler.kt:66)
    at io.kotless.local.handler.DynamicHandler.handle(DynamicHandler.kt:45)

Perhaps at least wrap the deserialization? So it can continue to process the HTTP Event?