Amazon SQS events.
def handle(event, _ctx, _state) do
sqs = Mayfly.Events.SQS.decode(event)
{:ok,
Mayfly.Events.SQS.process_batch(sqs, fn record ->
MyApp.Orders.process(record.body) # {:ok, _} | {:error, _} | raise
end)}
endprocess_batch/2 returns the partial-batch response
(%{batchItemFailures: [...]}) so that only failed messages are retried.
The event source mapping must be created with
FunctionResponseTypes=ReportBatchItemFailures for Lambda to honour it.
body is JSON-decoded when it parses, otherwise the raw string.
message_attributes is flattened to %{"name" => value} (string or binary
values; number values are returned as strings as SQS sends them).
Summary
Functions
Partial batch response for the given message ids.
Decodes an SQS event.
Runs fun for each record and returns the partial batch response listing
the records for which fun returned {:error, _}, raised, exited or threw.
Types
@type t() :: %Mayfly.Events.SQS{raw: map(), records: [Mayfly.Events.SQS.Record.t()]}
Functions
Partial batch response for the given message ids.
Decodes an SQS event.
@spec process_batch(t(), (Mayfly.Events.SQS.Record.t() -> term())) :: %{ batchItemFailures: [%{itemIdentifier: String.t()}] }
Runs fun for each record and returns the partial batch response listing
the records for which fun returned {:error, _}, raised, exited or threw.