0.1.14 • Published 10 months ago

@scloud/lambda-queue v0.1.14

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Lambda SQS handler

A Lambda handler that processes SQS messages and returns any batch item failures for retry.

This is a piece of useful boilerplate to handle the mechanics of processing a batch of messages, catching any errors and retrying failed messages.

See: https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting

Usage

Create your message processing function:

/**
 * Process a single SQS message.
 * It's safe to allow exceptions to be thrown.
 * Errors will be caught and handled as a batch item failure.
 */
export async function messageHandler(message: SQSRecord) {
  const slackWebhook = process.env.SLACK_WEBHOOK || '';
  if (slackWebhook) {
    await axios.post(slackWebhook, { text: `${message.body}` });
  } else {
    console.log(`Message would be sent to Slack: ${message.body} (process.env.SLACK_WEBHOOK isn't set)`);
  }
}

Call @scloud/lambda-queue from your Lambda handler:

import sqsHandler from '@scloud/lambda-queue'

export async function handler(event: SQSEvent, context: Context): Promise<SQSBatchResponse> {
  const result = await sqsHandler(messageHandler, event, context)
  return result;
}

The sqsHandler function will call your message handler for each item in the batch, catching any errors and returning an SQSBatchResponse with any failed message IDs so that Lambda can retry.

0.1.14

10 months ago

0.1.13

11 months ago

0.1.12

11 months ago

0.1.11

11 months ago

0.1.10

11 months ago

0.1.9

11 months ago

0.1.7

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago