Registry / messaging / sqs-producer-2

sqs-producer-2

JSON →
library2.1.2jsnpmunverified

A Node.js library for enqueuing messages to Amazon SQS queues. It provides a simple Producer class for creating producers with configuration for region, queue URL, and AWS credentials. Supports sending individual or batched messages, custom message IDs, delay seconds, message attributes, and FIFO queue parameters (groupId, deduplicationId). Includes queue size retrieval. Version 2.1.2 is the latest stable release. Ships TypeScript definitions. Designed for use with the AWS SDK v2 or v3 (v3 recommended). Key differentiators: simple API, direct use of AWS SDK config, and support for FIFO queues.

npm install sqs-producer-2
INSTALL
IMPORT
SIG · SQS-PRODUCER-2
S
sqs-producer-2
messagingjavascriptv2.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Producer
import { Producer } from 'sqs-producer'
const Producer = require('sqs-producer')
ESM import is available and preferred. CommonJS require still works but might have TypeScript issues.
Producer
const { Producer } = require('sqs-producer')
const producer = require('sqs-producer')
CommonJS destructuring is required; default export not available.
Producer
import type { Producer } from 'sqs-producer'
import { Producer } from 'sqs-producer' // in type-only context
For type-only imports, use `import type` to avoid runtime errors.

Creates an SQS producer, retrieves queue size, and sends two messages with different options.

import { Producer } from 'sqs-producer'; const producer = Producer.create({ queueUrl: process.env.SQS_QUEUE_URL ?? 'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name', region: process.env.AWS_REGION ?? 'eu-west-1', accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '', secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? '', }); async function main() { const size = await producer.queueSize(); console.log(`Queue size: ${size}`); await producer.send([ { id: '1', body: 'First message' }, { id: '2', body: 'Second message', delaySeconds: 5 }, ]); console.log('Messages sent'); } main().catch(console.error);
Debug
Known issues
breakingVersion 2.x uses AWS SDK v2 by default. For v3, you must pass a pre-configured SQS client via the `sqs` option.
fix
Use the `sqs` option with an AWS SDK v3 SQSClient instance.
affects: >=2.0.0
gotchaThe library expects the AWS SDK to be installed separately. If you use AWS SDK v3, you need to install @aws-sdk/client-sqs.
fix
Install aws-sdk (v2) or @aws-sdk/client-sqs (v3) as a dependency.
affects: *
deprecatedThe `Producer.create` method uses a callback-style AWS SDK v2 config. AWS SDK v2 is in maintenance mode.
fix
Consider migrating to AWS SDK v3 and use the `sqs` option.
affects: >=2.0.0
gotchaFor FIFO queues, you must provide `groupId` and optionally `deduplicationId`. Missing these will cause errors.
fix
Always include `groupId` and `deduplicationId` (if content-based dedup disabled) in the message object.
affects: *
gotchaThe `send` method does not support `delaySeconds` for individual messages in batch send (subject to AWS limits). The library sends messages in batches of up to 10.
fix
Ensure `delaySeconds` is within 0-900 and note that AWS limits per-message delay when batching.
affects: *
Errors
Common errors & fixes
Cannot find module 'aws-sdk'
Missing required peer dependency
fix
Install aws-sdk: npm install aws-sdk
TypeError: Producer.create is not a function
Importing the module incorrectly (e.g., default import instead of named)
fix
Use `import { Producer } from 'sqs-producer'` or `const { Producer } = require('sqs-producer')`
The queue URL is required
Missing queueUrl configuration in Producer.create
fix
Provide queueUrl option when creating producer.
MissingRequiredParameter: MissingRequiredParameter
AWS SDK missing region or credentials
fix
Set region and accessKeyId/secretAccessKey in producer config or environment variables.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies
aws-sdkrequiredRequired for SQS client; v2 or v3 compatible
Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
sqs-producer-2 — npm install sqs-producer-2 · libregistry