API Reference

sqs-consumer

High-level SQS consumer for Node.js that polls queues, extends visibility, and emits lifecycle events.

Official Documentation ↗
CompatibilityThis documentation covers version v15.0.4. Check the official docs for the latest API surface.

Installation

npmnpm install sqs-consumer @aws-sdk/client-sqs
pnpmpnpm add sqs-consumer @aws-sdk/client-sqs

Methods

Overview

sqs-consumer is a high-level SQS consumer that polls queues, extends visibility, and emits lifecycle events around message handling. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • Consumer.create — Builds a consumer bound to a queue URL with a message handling function.
  • consumer.start — Begins polling the queue and dispatching messages to the handler.
  • consumer events — Lifecycle events for observing throughput, empty polls, and failures.

Example

const { Consumer } = require('sqs-consumer');

const app = Consumer.create({
  queueUrl: process.env.QUEUE_URL,
  handleMessage: async (message) => {
    await process(message.Body);
  },
});

Notes

It deletes messages only after the handler resolves and keeps extending visibility to protect slow processing. Handlers should still be idempotent.

Verification

Start the consumer against a queue, send one message, and confirm a message_processed event fires once.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/bbc/sqs-consumer@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:41.087Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/bbc/sqs-consumer@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:41.087Z.

FAQ

How does it prevent a slow handler from losing messages?
It extends the message visibility timeout while handling and deletes the message only after handleMessage resolves.
How do I stop the consumer gracefully?
Call consumer.stop() so in-flight messages finish and no new ones are fetched, then clean up resources.
How do I tune throughput?
Adjust batchSize, pollingWaitTimeMs, and the number of consumer instances to match your processing capacity.