# 📨 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

```bash
# 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`

```js
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

```js
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:

1. Run LocalStack via Docker
```bash
docker run --rm -it -p 4566:4566 localstack/localstack
```

2. Create a queue via AWS CLI:
```bash
aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name your-queue-name
```

3. Set `.env` values:
```env
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](https://github.com/your-github)

---

## 🙋‍♂️ Questions or Contributions?

Feel free to open issues or PRs. Feedback and improvements are always welcome!

---

## 🔗 Useful Links

- [AWS SQS Documentation](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html)
- [LocalStack GitHub](https://github.com/localstack/localstack)
- [AWS SDK for JavaScript](https://github.com/aws/aws-sdk-js)
