> For the complete documentation index, see [llms.txt](https://docs.nestjstools.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nestjstools.com/broker-integration/amazon-sqs.md).

# Amazon SQS

### 📨 Amazon SQS Channel Integration

This extension enables seamless integration between `@nestjstools/messaging` and **Amazon Simple Queue Service (SQS)**. It supports both cloud-based and local queue setups (via ElasticMQ) for reliable, scalable, and distributed messaging.

***

#### 📦 Installation

```bash
npm install @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extension
```

or

```bash
yarn add @nestjstools/messaging @nestjstools/messaging-amazon-sqs-extension
```

***

#### ⚙️ Example Configuration

```ts
import { Module } from '@nestjs/common';
import { MessagingModule } from '@nestjstools/messaging';
import { MessagingAmazonSQSExtensionModule, AmazonSqsChannelConfig } from '@nestjstools/messaging-amazon-sqs-extension';
import { SendMessageHandler } from './handlers/send-message.handler';

@Module({
  imports: [
    MessagingAmazonSQSExtensionModule,
    MessagingModule.forRoot({
      messageHandlers: [SendMessageHandler],
      buses: [
        {
          name: 'sqs-event.bus',
          channels: ['sqs-event'],
        },
      ],
      channels: [
        new AmazonSqsChannelConfig({
          name: 'sqs-event',
          region: 'us-east-1',
          queueUrl: 'http://localhost:9324/queue/test_queue', // ElasticMQ for local use
          autoCreate: true,
          enableConsumer: true,
          credentials: {
            accessKeyId: 'x',
            secretAccessKey: 'x',
          },
          maxNumberOfMessages: 3,
          visibilityTimeout: 10,
          waitTimeSeconds: 5,
        }),
      ],
      debug: true,
    }),
  ],
})
export class AppModule {}
```

***

#### 🛠️ AmazonSqsChannelConfig Properties

| Property              | Description                                                        | Default Value |
| --------------------- | ------------------------------------------------------------------ | ------------- |
| `name`                | Name of the SQS channel (e.g., `'sqs-event'`).                     | —             |
| `region`              | AWS region for the queue (e.g., `'us-east-1'`).                    | —             |
| `queueUrl`            | Full URL of the SQS queue.                                         | —             |
| `credentials`         | Optional AWS credentials (accessKeyId & secretAccessKey).          | —             |
| `enableConsumer`      | Whether to enable consuming messages from this queue.              | `true`        |
| `autoCreate`          | Automatically create the queue if it doesn't exist.                | `true`        |
| `maxNumberOfMessages` | Number of messages to fetch in a single poll.                      | `1`           |
| `visibilityTimeout`   | Time (seconds) to hide a message after retrieval.                  | `20`          |
| `waitTimeSeconds`     | Duration (seconds) the consumer waits for messages (long polling). | `0`           |

***

#### 🌐 Cross-Language Communication

To integrate with external (non-NestJS) systems:

* **Publish a message** to the SQS queue.
* **Set the `messagingRoutingKey` header** to match your NestJS handler:

```ts
@MessageHandler('my_app_command.create_user') // routing key to use in SQS message attributes
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nestjstools.com/broker-integration/amazon-sqs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
