in dsl/ktor/cloud/ktor-lang-aws/src/main/kotlin/io/kotless/dsl/ktor/KotlessAWS.kt [45:92]
override fun handleRequest(input: InputStream, output: OutputStream, @Suppress("UNUSED_PARAMETER") any: Context?) {
if (!prepared) {
prepare(engine.application)
prepared = true
}
val response = try {
runBlocking {
val json = input.bufferedReader().use { it.readText() }
logger.info("Started handling request")
logger.debug("Request is {}", json)
if (json.contains("Scheduled Event")) {
val event = JSON.parse(CloudWatch.serializer(), json)
if (event.`detail-type` == "Scheduled Event" && event.source == "aws.events") {
logger.info("Request is Scheduled Event")
try {
engine.environment.monitor.raise(LambdaWarming, engine.application)
} catch (e: Throwable) {
logger.error("One or more of the LambdaWarming handlers thrown an exception", e)
}
return@runBlocking null
}
}
logger.info("Request is HTTP Event")
val request = JSON.parse(AwsHttpRequest.serializer(), json)
val call = KotlessCall(engine.application, request.toRequest())
engine.pipeline.execute(call)
call.response.toHttp()
}
} catch (e: Throwable) {
logger.error("Error occurred during handle of request and was not caught", e)
null
}
if (response != null) {
output.write(JSON.bytes(HttpResponse.serializer(), response))
} else {
logger.info("Got null response")
}
logger.info("Ended handling request")
}