sqs-producer-lib
v3.0.5
Published
Reusable AWS SQS producer library for Node.js microservices
Maintainers
Readme
📨 AWS SQS Client (Class-based)
A reusable Node.js library using a class-based wrapper to send messages to AWS SQS queues.
Seamlessly supports both LocalStack for local testing and AWS SQS for production with dynamic queue URLs.
🚀 Features
- ✅ Class-based, object-oriented design
- 🌍 Works with both LocalStack and AWS
- ⚙️ Customizable with constructor config
- 🛡 Helpful console logs and robust error handling
- 📦 Easy to plug into any Node.js project
📦 Installation
# Local path install
npm install /path/to/your/sqs-client-lib
# OR if published as npm package
npm install @your-org/sqs-client🛠️ Usage
1. Import and create an instance of SQSClient
const SQSClient = require('./src/SQSClient');
const sqsClient = new SQSClient({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION || 'us-east-1',
useLocalstack: process.env.USE_LOCALSTACK === 'true',
localstackEndpoint: process.env.LOCALSTACK_ENDPOINT || 'http://localhost:4566',
accountId: process.env.AWS_ACCOUNT_ID || '000000000000',
});2. Send a message to the queue
const message = {
orderId: '123456',
action: 'order_placed',
};
sqsClient.sendMessage('your-queue-name', message)
.then((res) => console.log('✅ Message ID:', res.MessageId))
.catch((err) => console.error('❌ Error:', err.message));⚙️ Config Options
You can pass these to the constructor:
| Option | Type | Description | Default |
|----------------------|----------|------------------------------------------|-------------------------|
| accessKeyId | string | AWS access key | Required |
| secretAccessKey | string | AWS secret key | Required |
| region | string | AWS region | us-east-1 |
| useLocalstack | boolean | Enable LocalStack | false |
| localstackEndpoint | string | LocalStack endpoint | http://localhost:4566 |
| accountId | string | AWS account ID | 000000000000 |
📂 Project Structure Example
your-project/
├── src/
│ └── SQSClient.js # This file
├── example.js # How you use the client
├── .env # Store environment variables here
└── README.md # You're here!🧪 LocalStack Testing
Step-by-step:
- Run LocalStack via Docker
docker run --rm -it -p 4566:4566 localstack/localstack- Create a queue via AWS CLI:
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name your-queue-name- Set
.envvalues:
USE_LOCALSTACK=true
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
AWS_REGION=us-east-1
LOCALSTACK_ENDPOINT=http://localhost:4566
AWS_ACCOUNT_ID=000000000000📜 License
MIT License
© 2025 Kenit Goswami
🙋♂️ Questions or Contributions?
Feel free to open issues or PRs. Feedback and improvements are always welcome!
