-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleSqsEventHandler.scala
More file actions
34 lines (27 loc) · 1005 Bytes
/
ExampleSqsEventHandler.scala
File metadata and controls
34 lines (27 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.encalmo.lambda.example
import org.encalmo.aws.AwsClient
import org.encalmo.aws.AwsSqsApi
import org.encalmo.lambda.*
import upickle.default.*
object ExampleSqsEventHandler extends SqsEventHandler[AwsClient] {
override def functionName: Option[String] = Some("SendTargetEvent")
case class Event(name: String) derives ReadWriter
override def handleRecord(record: SqsEvent.Record)(using LambdaContext, AwsClient): Option[String] = {
println(record.body)
record
.maybeParseBodyAs[Event]
.map(sendTargetEvent)
}
def sendTargetEvent(event: Event)(using context: LambdaContext, aws: AwsClient): String =
val greeting = s"Hello ${event.name}!"
context
.maybeGetProperty("TARGET_SQS_QUEUE_URL")
.map { queueUrl =>
val messageId = AwsSqsApi.sendMessage(queueUrl, greeting).messageId()
println(s"Message $messageId sent to $queueUrl")
}
.getOrElse {
println("TARGET_SQS_QUEUE_URL not defined")
}
""
}