Skip to content

API reference / @node-ts/bus-sqs-lambda / BusSqsLambdaReceiver

Class: BusSqsLambdaReceiver ​

Defined in: bus-sqs-lambda-receiver.ts:26

Receives messages from an SQS event that's triggered a lambda function, and converts them into a TransportMessage ready to be dispatched. A message that fails, or that a handler returns with bus.returnMessage(), is retried by Lambda: either on its own (reportBatchItemFailures) or with the whole batch.

Example ​

ts
const bus = Bus.configure()
  .withTransport(sqsTransport)
  .withReceiver(new BusSqsLambdaReceiver({ reportBatchItemFailures: true }))
  .build()

export const handler: SQSHandler = event => bus.receive<SQSBatchResponse>(event)

Implements ​

Constructors ​

Constructor ​

ts
new BusSqsLambdaReceiver(configuration?): BusSqsLambdaReceiver;

Defined in: bus-sqs-lambda-receiver.ts:34

Parameters ​

ParameterTypeDescription
configurationBusSqsLambdaReceiverConfigurationOptions for how the outcome of a batch is reported back to Lambda

Returns ​

BusSqsLambdaReceiver

Methods ​

receive() ​

ts
receive(receivedMessage, messageSerializer): Promise<TransportMessage<SqsLambdaRecord>[]>;

Defined in: bus-sqs-lambda-receiver.ts:38

Invoked when a message is received by the application and needs to be converted into a transport message so that it can be passed to the dispatcher and send to handlers.

Parameters ​

ParameterTypeDescription
receivedMessageSQSEventThe message received by the app
messageSerializerMessageSerializerThe configured serializer, which can be used to deserialize the incoming message

Returns ​

Promise<TransportMessage<SqsLambdaRecord>[]>

Implementation of ​

Receiver.receive


toReceiveResult() ​

ts
toReceiveResult(failures): void | SQSBatchResponse;

Defined in: bus-sqs-lambda-receiver.ts:63

Reports the records that failed back to Lambda once the whole batch has been handled.

Parameters ​

ParameterTypeDescription
failuresReceivedMessageFailure<TransportMessage<SqsLambdaRecord>>[]The records that failed to be handled

Returns ​

void | SQSBatchResponse

An SQSBatchResponse of the failed records when reportBatchItemFailures is enabled

Throws ​

the first failure's error when reportBatchItemFailures is disabled, so Lambda retries the whole batch

Implementation of ​

Receiver.toReceiveResult

Released under the MIT License.