# sqs-producer

> Enqueues messages onto a given SQS queue

Latest version **9.0.5** (published 2026-05-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install sqs-producer
pnpm add sqs-producer
yarn add sqs-producer
bun add sqs-producer
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 9.0.5 |
| Published | 2026-05-21 |
| First published | 2014-12-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.0.0 |
| Dependencies | 1 |
| Unpacked size | 58.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 217 |
| Maintainers | ibl, nicholasgriffin_bbc |
| Keywords | aws-sqs, backend, message-queue, nodejs, queue-producer, serverless, sqs |

## Links

- npm: https://www.npmjs.com/package/sqs-producer
- Repository: https://github.com/bbc/sqs-producer
- Homepage: https://bbc.github.io/sqs-producer/
- Issues: https://github.com/bbc/sqs-producer/issues
- npm.io page: https://npm.io/package/sqs-producer

## Dependencies (1)

- [@aws-sdk/client-sqs](https://npm.io/package/@aws-sdk/client-sqs.md) ^3.1036.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 9.0.5 (latest) — 2026-05-21
- 9.0.0-canary.2 (canary) — 2026-05-02
- 9.0.4 — 2026-05-21
- 9.0.3 — 2026-05-21
- 9.0.2 — 2026-05-08
- 9.0.1 — 2026-05-02
- 9.0.0 — 2026-05-02
- 9.0.0-canary.1 — 2026-05-02
- 8.0.9-canary.5 — 2026-05-02
- 8.0.9 — 2026-04-19
- 8.0.9-canary.4 — 2026-04-19
- 8.0.9-canary.3 — 2026-04-19
- 8.0.9-canary.2 — 2026-04-19
- 8.0.9-canary.1 — 2026-04-19
- 8.0.8 — 2026-04-19
- … 86 more at https://npm.io/package/sqs-producer/versions

## README

# sqs-producer

[![NPM downloads](https://img.shields.io/npm/dm/sqs-producer.svg?style=flat)](https://npmjs.org/package/sqs-producer)
[![Build Status](https://github.com/bbc/sqs-producer/actions/workflows/test.yml/badge.svg)](https://github.com/bbc/sqs-producer/actions/workflows/test.yml)

Enqueues messages onto a given SQS queue.

## Installation

To install this package, enter the following command into your terminal (or the variant of whatever package manager you are using):

```
npm install sqs-producer
```

### Node version

We will only support Node versions that are actively or security supported by the Node team. You can find the list of versions that are actively supported [here](https://nodejs.org/en/about/releases/).

## Documentation

Visit [https://bbc.github.io/sqs-producer/](https://bbc.github.io/sqs-producer/) for the full API documentation.

## Usage

```js
import { Producer } from "sqs-producer";
import { SQSClient } from "@aws-sdk/client-sqs";

// create simple producer
const producer = Producer.create({
  queueUrl: "https://sqs.eu-west-1.amazonaws.com/account-id/queue-name",
  region: "eu-west-1",
});

// send messages to the queue
await producer.send(["msg1", "msg2"]);

// get the current size of the queue
const size = await producer.queueSize();
console.log(`There are ${size} messages on the queue.`);

// send a message to the queue with a specific ID (by default the body is used as the ID)
await producer.send([
  {
    id: "id1",
    body: "Hello world",
  },
]);

// send a message to the queue with
// - delaySeconds (must be an number contained within 0 and 900)
// - messageAttributes
await producer.send([
  {
    id: "id1",
    body: "Hello world with two string attributes: attr1 and attr2",
    messageAttributes: {
      attr1: { DataType: "String", StringValue: "stringValue" },
      attr2: { DataType: "Binary", BinaryValue: new Buffer("binaryValue") },
    },
  },
  {
    id: "id2",
    body: "Hello world delayed by 5 seconds",
    delaySeconds: 5,
  },
]);

// send a message to a FIFO queue
//
// note that AWS FIFO queues require two additional params:
// - groupId (string)
// - deduplicationId (string)
//
// deduplicationId can be excluded if content-based deduplication is enabled
//
// https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-queue-recommendations.html
await producer.send({
  id: "testId",
  body: "Hello world from our FIFO queue!",
  groupId: "group1234",
  deduplicationId: "abcdef123456", // typically a hash of the message body
});

// send messages to a standard queue with groupId for fair queue behavior
//
// Fair queues automatically mitigate noisy neighbor impact in multi-tenant queues
// by using groupId to identify tenants and ensure fair resource allocation
//
// https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fair-queues.html
await producer.send([
  {
    id: "msg1",
    body: "Message from tenant A",
    groupId: "tenant-a",
  },
  {
    id: "msg2",
    body: "Message from tenant B",
    groupId: "tenant-b",
  },
]);
```

### Credentials

By default the producer will look for AWS credentials in the places [specified by the AWS SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials). The simplest option is to export your credentials as environment variables:

```bash
export AWS_SECRET_ACCESS_KEY=...
export AWS_ACCESS_KEY_ID=...
```

If you need to specify your credentials manually, you can use a pre-configured instance of the [SQS Client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/classes/sqsclient.html) client.

```js
import { Producer } from "sqs-producer";
import { SQSClient } from "@aws-sdk/client-sqs";

// create simple producer
const producer = Producer.create({
  queueUrl: "https://sqs.eu-west-1.amazonaws.com/account-id/queue-name",
  region: "eu-west-1",
  sqs: new SQSClient({
    region: "my-region",
    credentials: {
      accessKeyId: "yourAccessKey",
      secretAccessKey: "yourSecret",
    },
  }),
});

// send messages to the queue
await producer.send(["msg1", "msg2"]);
```

## Development

### Test

```bash
npm test
```

### Coverage

For coverage report, run the command:

```bash
npm run coverage
```

### Lint

To check for problems using ESLint

```bash
npm run lint
```

## Contributing

We welcome and appreciate contributions for anyone who would like to take the time to fix a bug or implement a new feature.

But before you get started, [please read the contributing guidelines](https://github.com/bbc/sqs-producer/blob/main/.github/CONTRIBUTING.md) and [code of conduct](https://github.com/bbc/sqs-producer/blob/main/.github/CODE_OF_CONDUCT.md).

## License

SQS Producer is distributed under the Apache License, Version 2.0, see [LICENSE](./LICENSE) for more information.

---
_Source: https://npm.io/package/sqs-producer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
