{"id":34835,"date":"2025-01-28T19:01:37","date_gmt":"2025-01-28T13:31:37","guid":{"rendered":"https:\/\/mobisoftinfotech.com\/resources\/?p=34835"},"modified":"2026-01-05T15:21:51","modified_gmt":"2026-01-05T09:51:51","slug":"aws-sqs-sns-nestjs-typescript-tutorial","status":"publish","type":"post","link":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial","title":{"rendered":"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript"},"content":{"rendered":"<p>In microservices architectures, AWS SQS and SNS are essential services for connecting and managing communication between distributed systems. In this blog post, we will guide you through setting up AWS SQS and AWS SNS in a NestJS project using TypeScript. You\u2019ll also learn how to use the SNS fan-out pattern to broadcast messages and subscribe to those messages using SQS.<\/p>\n\n\n\n<p>Additionally, you will get the full setup, including SQLite database integration to save processed messages and SQS polling to automatically process and manage messages from the queue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>SNS Fanout Pattern:<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"1200\" height=\"582\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/sns-fanout-pattern-event-driven-architecture.png\" alt=\"SNS Fanout Pattern for Event-Driven Architecture\" class=\"wp-image-34847\" title=\"SNS Fanout Pattern for Event-Driven Architecture in AWS\"><\/noscript><img decoding=\"async\" width=\"1200\" height=\"582\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201200%20582%22%3E%3C%2Fsvg%3E\" alt=\"SNS Fanout Pattern for Event-Driven Architecture\" class=\"wp-image-34847 lazyload\" title=\"SNS Fanout Pattern for Event-Driven Architecture in AWS\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/sns-fanout-pattern-event-driven-architecture.png\"><\/figure>\n\n\n\n<p>The SNS fan-out pattern is a mechanism through which a single message is sent to multiple subscribers. Instead of sending separate messages to each subscriber, a message is published to an SNS topic, and multiple subscribers consume it through SQS or other supported endpoints.<\/p>\n\n\n\n<p>For example, consider a scenario where we have an Order Service, Invoice Service, and Order-Tracking Shipment Service. When a message is published to an SNS topic, such as order-created, by the Order Service, other services can listen to the message through SQS and begin processing it.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Invoice Service will generate an invoice for the order.<\/li>\n\n\n\n<li>The Order-Tracking Shipment Service will initiate order tracking and shipment.<\/li>\n<\/ul>\n\n\n\n<p>This allows for efficient and decoupled message handling across multiple services.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Setting Up a NestJS Project with SQS and SNS.<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Prerequisites<\/strong><\/h3>\n\n\n\n<p>1. Basic understanding of NestJS.<br>2. An AWS account.<br>3. Familiarity with SQS (Simple Queue Service) and SNS (Simple Notification Service).<br>4. Node.js installed on your system.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/contact-us?utm_source=blog&amp;utm_medium=referral&amp;utm_campaign=aws-sqs-sns-nestjs-typescript-tutorial-cta1\"><noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/start-building-aws-sqs-sns-nestjs.png\" alt=\"Start building with AWS SQS and SNS in NestJS\" class=\"wp-image-34854\" title=\"Start Building with AWS SQS &amp; SNS in NestJS Today\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20150%22%3E%3C%2Fsvg%3E\" alt=\"Start building with AWS SQS and SNS in NestJS\" class=\"wp-image-34854 lazyload\" title=\"Start Building with AWS SQS &amp; SNS in NestJS Today\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/start-building-aws-sqs-sns-nestjs.png\"><\/a><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 1: Setting Up NestJS<\/strong><\/h4>\n\n\n\n<p>First, create a new NestJS project:<br><code>npx @nestjs\/cli new nest--project<\/code><br>Follow the CLI prompts to complete the setup.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 2: Install Required Dependencies<\/strong><\/h4>\n\n\n\n<h5 class=\"font-change-color\">1. Navigate to the project Directory<\/h5>\n\n\n\n<p><code>cd nest-project<\/code><\/p>\n\n\n\n<h5 class=\"font-change-color\">2. Install the AWS SDK modules for SQS and SNS, along with other necessary packages:<\/h5>\n\n\n\n<p><code>npm install @aws-sdk\/client-sns @aws-sdk\/client-sqs<\/code><\/p>\n\n\n\n<h5 class=\"font-change-color\">3. Install additional dependencies for SQS polling and database support:<\/h5>\n\n\n\n<p><code>npm install&nbsp; sqs-consumer @nestjs\/typeorm typeorm sqlite3<\/code><\/p>\n\n\n\n<h5 class=\"font-change-color\">4. Install other dependencies&nbsp;<\/h5>\n\n\n\n<p><code>npm install @nestjs\/config uuid dotenv<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 3: Configure Environment Variables<\/strong><\/h4>\n\n\n\n<p>Create a <code>.env<\/code> file in the root of your project and add your AWS credentials:<\/p>\n\n\n\n<p><code>AWS_ACCESS_KEY_ID=&lt;your-access-key-id&gt;<\/code><\/p>\n\n\n\n<p><code>AWS_SECRET_ACCESS_KEY=&lt;your-secret-access-key&gt;<\/code><\/p>\n\n\n\n<p><code>AWS_REGION=&lt;your-region&gt;<\/code><\/p>\n\n\n\n<p><code>SNS_TOPIC_ARN=&lt;your-sns-topic-arn&gt;<\/code><\/p>\n\n\n\n<p><code>SQS_QUEUE_URL=&lt;your-sqs-queue-url&gt;<\/code><br><br>Load these variables globally using NestJS&#8217;s ConfigModule, and update imports in <code>app.module.ts<\/code><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">@Module({\n <span class=\"hljs-attr\">imports<\/span>: &#091;\n  ConfigModule.forRoot({\n   <span class=\"hljs-attr\">isGlobal<\/span>: <span class=\"hljs-literal\">true<\/span>, <span class=\"hljs-comment\">\/\/ Makes the configuration available globally<\/span>\n  }),\n ],\n\u2026\n})\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 4: Set Up SQS in AWS<\/strong><\/h4>\n\n\n\n<h5 class=\"font-change\"><strong>1. Create an SQS Queue:<\/strong><\/h5>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>1. Log in to the AWS Management Console.<\/p>\n\n\n\n<p>2. Navigate to the SQS service.<\/p>\n\n\n\n<p>3. Click on Create Queue.<\/p>\n\n\n\n<p>4. Choose either a Standard or FIFO queue based on your needs.<\/p>\n\n\n\n<p>5. Configure the queue settings (e.g., name, visibility timeout).<\/p>\n\n\n\n<p>6. Click Create Queue.<\/p>\n<\/div><\/div>\n\n\n\n<p>For more details, refer to the<a href=\"https:\/\/docs.aws.amazon.com\/sqs\/\" target=\"_blank\" rel=\"noreferrer noopener\"> Amazon SQS Documentation<\/a>.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 5: Set Up SNS in AWS<\/strong><\/h4>\n\n\n\n<h5 class=\"font-change\"><strong>1. Create an SNS Topic:<\/strong><\/h5>\n\n\n\n<p>1. Navigate to the SNS service in the AWS Management Console.<\/p>\n\n\n\n<p>2. Click on Create topic.<\/p>\n\n\n\n<p>3. Choose either a Standard or FIFO topic based on your requirements.<\/p>\n\n\n\n<p>4. Enter a name for your topic and configure additional settings.<\/p>\n\n\n\n<p>5. Click Create topic.<\/p>\n\n\n\n<h5 class=\"font-change\"><strong>2. Subscribe to the SQS Queue to the SNS Topic:<\/strong><\/h5>\n\n\n\n<p>1. Navigate to your SNS topic.<\/p>\n\n\n\n<p>2. Click Create Subscription.<\/p>\n\n\n\n<p>3. Choose Amazon SQS as the protocol.<\/p>\n\n\n\n<p>4. Enter the ARN of your SQS queue.<\/p>\n\n\n\n<p>5. Click Create Subscription.<\/p>\n\n\n\n<p>6. Add permissions to allow SNS to publish to your SQS queue.<\/p>\n\n\n\n<p>For more details on SNS, check out the<a href=\"https:\/\/docs.aws.amazon.com\/sns\/\" target=\"_blank\" rel=\"noreferrer noopener\"> <strong>Amazon SNS Documentation<\/strong><\/a><strong>.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"1200\" height=\"390\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/aws-nestjs-integration-logo.png\" alt=\"AWS and NestJS integration logos\" class=\"wp-image-34856\" title=\"AWS and NestJS Integration for Scalable Applications\"><\/noscript><img decoding=\"async\" width=\"1200\" height=\"390\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201200%20390%22%3E%3C%2Fsvg%3E\" alt=\"AWS and NestJS integration logos\" class=\"wp-image-34856 lazyload\" title=\"AWS and NestJS Integration for Scalable Applications\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/aws-nestjs-integration-logo.png\"><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 6: Configure SQLite database in NestJS:<\/strong><\/h4>\n\n\n\n<h5 class=\"font-change\"><strong>1. Create the SqsMessage Entity:<\/strong><\/h5>\n\n\n\n<p>Define the <code>SqsMessage<\/code> entity in <code>sqs\/models\/sqs-message.ts<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { Entity, PrimaryGeneratedColumn, Column } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'typeorm'<\/span>;\n\n@Entity({ <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">'sqs_message'<\/span> })\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SqsMessage<\/span> <\/span>{\n @PrimaryGeneratedColumn()\n <span class=\"hljs-attr\">id<\/span>: number;\n\n @Column()\n <span class=\"hljs-attr\">messageId<\/span>: string;\n\n @Column({ <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">'message_body'<\/span> })\n <span class=\"hljs-attr\">messageBody<\/span>: string;\n\n @Column({ <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">'processed_at'<\/span> })\n <span class=\"hljs-attr\">processedAt<\/span>: <span class=\"hljs-built_in\">Date<\/span>;\n\n @Column({ <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">'message'<\/span> })\n <span class=\"hljs-attr\">message<\/span>: string;\n\n @Column({ <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">'source_type'<\/span> })\n <span class=\"hljs-attr\">sourceType<\/span>: string;\n\n @Column({ <span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">'deleted_at'<\/span>, <span class=\"hljs-attr\">nullable<\/span>: <span class=\"hljs-literal\">true<\/span> })\n deletedAt?: <span class=\"hljs-built_in\">Date<\/span>;\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>2. Create the Data Access Object for SqsMessage:<\/strong><\/h5>\n\n\n\n<h5 class=\"wp-block-heading\"><\/h5>\n\n\n\n<p>Create <code>sqs\/daos\/sqs-message.dao.ts<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { Injectable } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { DataSource } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'typeorm'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsMessage } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'..\/models\/sqs-message'<\/span>;\n\n@Injectable()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SqsMessageDao<\/span> <\/span>{\n<span class=\"hljs-keyword\">constructor<\/span>(private readonly dataSource: DataSource) {}\npublic <span class=\"hljs-keyword\">async<\/span> createSqsMessage(message: SqsMessage): <span class=\"hljs-built_in\">Promise<\/span>&lt;SqsMessage&gt; {\n <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.dataSource.manager.transaction(<span class=\"hljs-keyword\">async<\/span> (manager) =&gt; {\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">await<\/span> manager.save(message);\n });\n}\n\n public <span class=\"hljs-keyword\">async<\/span> getSqsMessageById(messageId: string): <span class=\"hljs-built_in\">Promise<\/span>&lt;SqsMessage&gt; {\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.dataSource.manager.transaction(<span class=\"hljs-keyword\">async<\/span> (manager) =&gt; {\n   <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">await<\/span> manager\n    .createQueryBuilder()\n    .select(<span class=\"hljs-string\">'s'<\/span>)\n    .from(SqsMessage, <span class=\"hljs-string\">'s'<\/span>)\n    .where(<span class=\"hljs-string\">'s.deletedAt IS NULL'<\/span>)\n    .andWhere(<span class=\"hljs-string\">'s.messageId = :messageId'<\/span>, { messageId })\n    .getOne();\n  });\n }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>3. Create an enum for Message Source Type <code>sqs\/utils\/constants.ts<\/code><\/strong><\/h5>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">export<\/span> enum MessageSourceType {\n SQS = <span class=\"hljs-string\">'SQS'<\/span>,\n SNS = <span class=\"hljs-string\">'SNS'<\/span>,\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>4. Configure TypeORM:<\/strong><\/h5>\n\n\n\n<p>Update <code>app.module.ts<\/code> to include <code>TypeORM<\/code> configuration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">@Module({\n<span class=\"hljs-attr\">imports<\/span>: &#091;\n \u2026\n TypeOrmModule.forRoot({\n  <span class=\"hljs-attr\">type<\/span>: <span class=\"hljs-string\">'sqlite'<\/span>,\n  <span class=\"hljs-attr\">database<\/span>: <span class=\"hljs-string\">'sqlite.db'<\/span>,\n  <span class=\"hljs-attr\">entities<\/span>: &#091;SqsMessage],\n  <span class=\"hljs-attr\">synchronize<\/span>: <span class=\"hljs-literal\">true<\/span>, \n }),\n TypeOrmModule.forFeature(&#091;SqsMessage]),\n \u2026\n],\n\u2026\n})<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 7:&nbsp; Implement SQS in NestJS<\/strong><\/h4>\n\n\n\n<h5 class=\"font-change\"><strong>1. Create the SQS Producer Service:<\/strong><\/h5>\n\n\n\n<p>Create <code>sqs\/sqs.producer.service.ts<\/code> to send messages to SQS:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { SendMessageCommand, SQSClient } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@aws-sdk\/client-sqs'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { Injectable } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { ConfigService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/config'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { v4 <span class=\"hljs-keyword\">as<\/span> uuid } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'uuid'<\/span>;\n\n@Injectable()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SqsProducerService<\/span> <\/span>{\n private sqsClient: SQSClient;\n private queueUrl: string;\n\n <span class=\"hljs-keyword\">constructor<\/span>(private configService: ConfigService) {\n  <span class=\"hljs-keyword\">this<\/span>.sqsClient = <span class=\"hljs-keyword\">new<\/span> SQSClient({\n   <span class=\"hljs-attr\">region<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_REGION'<\/span>),\n   <span class=\"hljs-attr\">credentials<\/span>: {\n    <span class=\"hljs-attr\">accessKeyId<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_ACCESS_KEY_ID'<\/span>),\n    <span class=\"hljs-attr\">secretAccessKey<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_SECRET_ACCESS_KEY'<\/span>),\n   },\n  });\n  <span class=\"hljs-keyword\">this<\/span>.queueUrl = <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'SQS_QUEUE_URL'<\/span>);\n}\n\n<span class=\"hljs-keyword\">async<\/span> sendMessage(message: string) {\n <span class=\"hljs-keyword\">try<\/span> {\n  <span class=\"hljs-keyword\">const<\/span> command = <span class=\"hljs-keyword\">new<\/span> SendMessageCommand({\n   <span class=\"hljs-attr\">QueueUrl<\/span>: <span class=\"hljs-keyword\">this<\/span>.queueUrl,\n   <span class=\"hljs-attr\">MessageBody<\/span>: message,\n   <span class=\"hljs-attr\">MessageGroupId<\/span>: <span class=\"hljs-string\">'sqs-message-group'<\/span>,\n   <span class=\"hljs-attr\">MessageDeduplicationId<\/span>: uuid(),\n  });\n\n  <span class=\"hljs-keyword\">const<\/span> response = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.sqsClient.send(command);\n  <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'SQS message sent: '<\/span>, message);\n  <span class=\"hljs-keyword\">return<\/span> response;\n }<span class=\"hljs-keyword\">catch<\/span> (error) {\n  <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'error'<\/span>, error);\n  }\n }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>2. Create the SQS Consumer Service:<\/strong><\/h5>\n\n\n\n<p>Create <code>sqs\/sqs.consumer.service.ts<\/code> to integrate <code>sqs-consumer<\/code> for polling messages.<\/p>\n\n\n\n<p>Implement logic to process each message, save it in the SQLite database, handle duplicates by checking for existing records, and delete processed messages from the queue.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/* eslint-disable @typescript-eslint\/no-unused-vars *\/<\/span>\n<span class=\"hljs-keyword\">import<\/span> { DeleteMessageCommand, Message, SQSClient } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@aws-sdk\/client-sqs'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { Injectable, OnModuleDestroy, OnModuleInit } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { ConfigService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/config'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { Consumer } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'sqs-consumer'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsMessageDao } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/daos\/sqs-message.dao'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsMessage } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/models\/sqs-message'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { MessageSourceType } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/utils\/constants'<\/span>;\n\n@Injectable()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SqsConsumerService<\/span> <span class=\"hljs-title\">implements<\/span> <span class=\"hljs-title\">OnModuleInit<\/span>, <span class=\"hljs-title\">OnModuleDestroy<\/span> <\/span>{\n private sqsClient: SQSClient;\n private queueUrl: string;\n private consumer: Consumer;\n\n <span class=\"hljs-keyword\">constructor<\/span>(\n  private configService: ConfigService,\n  private sqsMessageDao: SqsMessageDao,\n ){\n  <span class=\"hljs-keyword\">this<\/span>.sqsClient = <span class=\"hljs-keyword\">new<\/span> SQSClient({\n   <span class=\"hljs-attr\">region<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_REGION'<\/span>),\n   <span class=\"hljs-attr\">credentials<\/span>: {\n    <span class=\"hljs-attr\">accessKeyId<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_ACCESS_KEY_ID'<\/span>),\n    <span class=\"hljs-attr\">secretAccessKey<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_SECRET_ACCESS_KEY'<\/span>),\n   },\n  });\n  <span class=\"hljs-keyword\">this<\/span>.queueUrl = <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'SQS_QUEUE_URL'<\/span>);\n}\n\n<span class=\"hljs-keyword\">async<\/span> deleteConsumedMessage(receiptHandle: string) {\n <span class=\"hljs-keyword\">try<\/span> {\n  <span class=\"hljs-keyword\">const<\/span> command = <span class=\"hljs-keyword\">new<\/span> DeleteMessageCommand({\n   <span class=\"hljs-attr\">QueueUrl<\/span>: <span class=\"hljs-keyword\">this<\/span>.queueUrl,\n   <span class=\"hljs-attr\">ReceiptHandle<\/span>: receiptHandle,\n  });\n\n  <span class=\"hljs-keyword\">const<\/span> response = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.sqsClient.send(command);\n  <span class=\"hljs-keyword\">return<\/span> response;\n }<span class=\"hljs-keyword\">catch<\/span> (error) {\n  <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'Delete message error'<\/span>, error);\n }\n}\n\n public <span class=\"hljs-keyword\">async<\/span> onModuleInit(): <span class=\"hljs-built_in\">Promise<\/span>&lt;<span class=\"hljs-keyword\">void<\/span>&gt; {\n  <span class=\"hljs-keyword\">this<\/span>.pollMessages();\n}\n\nprivate formatSQSMessage(message: Message) {\n <span class=\"hljs-keyword\">const<\/span> messageBody = message.Body;\n <span class=\"hljs-keyword\">let<\/span> sourceType = <span class=\"hljs-string\">''<\/span>;\n <span class=\"hljs-keyword\">let<\/span> messageText = <span class=\"hljs-string\">''<\/span>;\n <span class=\"hljs-keyword\">try<\/span> {\n  <span class=\"hljs-keyword\">const<\/span> parsedMessageBody = <span class=\"hljs-built_in\">JSON<\/span>.parse(messageBody);\n  <span class=\"hljs-keyword\">if<\/span>(parsedMessageBody &amp;&amp; parsedMessageBody.Message) {\n    messageText = parsedMessageBody.Message;\n   }\n  <span class=\"hljs-keyword\">if<\/span>(\n   parsedMessageBody?.Type === <span class=\"hljs-string\">'Notification'<\/span> &amp;&amp;\n   parsedMessageBody?.TopicArn\n  ){\n   sourceType = MessageSourceType.SNS;\n  }<span class=\"hljs-keyword\">else<\/span> <span class=\"hljs-keyword\">if<\/span> (messageBody) {\n   messageText = messageBody;\n   sourceType = MessageSourceType.SQS;\n  }\n }<span class=\"hljs-keyword\">catch<\/span> (error) {\n  sourceType = MessageSourceType.SQS;\n  messageText = messageBody;\n }\n <span class=\"hljs-keyword\">return<\/span> {\n  <span class=\"hljs-attr\">messageText<\/span>: messageText,\n  <span class=\"hljs-attr\">sourceType<\/span>: sourceType,\n };\n}\n\nprivate <span class=\"hljs-keyword\">async<\/span> saveMessageInDb(message: Message) {\n <span class=\"hljs-keyword\">const<\/span> { messageText, sourceType } = <span class=\"hljs-keyword\">this<\/span>.formatSQSMessage(message);\n\n <span class=\"hljs-keyword\">const<\/span> sqsMessage = <span class=\"hljs-keyword\">new<\/span> SqsMessage();\n sqsMessage.messageId = message.MessageId;\n sqsMessage.messageBody = message.Body;\n sqsMessage.processedAt = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-built_in\">Date<\/span>();\n sqsMessage.sourceType = sourceType;\n sqsMessage.message = messageText;\n\n <span class=\"hljs-keyword\">this<\/span>.sqsMessageDao.createSqsMessage(sqsMessage);\n}\n\nprivate <span class=\"hljs-keyword\">async<\/span> processMessage(message: Message) {\n <span class=\"hljs-keyword\">const<\/span> sqsMessageFromDb = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.sqsMessageDao.getSqsMessageById(\n  message.MessageId,\n );\n\n  <span class=\"hljs-keyword\">if<\/span>(!sqsMessageFromDb || !sqsMessageFromDb.processedAt) {\n    <span class=\"hljs-comment\">\/\/process message<\/span>\n    <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'Received new message:'<\/span>, message.Body);\n    <span class=\"hljs-keyword\">this<\/span>.saveMessageInDb(message);\n   }\n  <span class=\"hljs-keyword\">this<\/span>.deleteConsumedMessage(message.ReceiptHandle);\n}\n\n private pollMessages = <span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n   <span class=\"hljs-keyword\">this<\/span>.consumer = Consumer.create({\n   <span class=\"hljs-attr\">queueUrl<\/span>: <span class=\"hljs-keyword\">this<\/span>.queueUrl,\n   <span class=\"hljs-attr\">handleMessage<\/span>: <span class=\"hljs-keyword\">async<\/span> (message: Message) =&gt; {\n    <span class=\"hljs-keyword\">this<\/span>.processMessage(message);\n   },\n   <span class=\"hljs-attr\">waitTimeSeconds<\/span>: <span class=\"hljs-number\">1<\/span>,\n   <span class=\"hljs-attr\">pollingWaitTimeMs<\/span>: <span class=\"hljs-number\">2000<\/span>, <span class=\"hljs-comment\">\/\/configure polling wait time<\/span>\n   <span class=\"hljs-attr\">shouldDeleteMessages<\/span>: <span class=\"hljs-literal\">false<\/span>, <span class=\"hljs-comment\">\/\/if set to true, consumer will delete the messages<\/span>\n   <span class=\"hljs-attr\">sqs<\/span>: <span class=\"hljs-keyword\">this<\/span>.sqsClient,\n  });\n\n  <span class=\"hljs-keyword\">this<\/span>.consumer.on(<span class=\"hljs-string\">'error'<\/span>, (err) =&gt; {\n   <span class=\"hljs-built_in\">console<\/span>.error(err.message);\n  });\n\n  <span class=\"hljs-keyword\">this<\/span>.consumer.on(<span class=\"hljs-string\">'processing_error'<\/span>, (err) =&gt; {\n   <span class=\"hljs-built_in\">console<\/span>.error(err.message);\n  });\n\n  <span class=\"hljs-keyword\">this<\/span>.consumer.on(<span class=\"hljs-string\">'timeout_error'<\/span>, (err) =&gt; {\n   <span class=\"hljs-built_in\">console<\/span>.error(err.message);\n  });\n\n  <span class=\"hljs-keyword\">this<\/span>.consumer.start();\n };\n\n public <span class=\"hljs-keyword\">async<\/span> onModuleDestroy() {\n  <span class=\"hljs-keyword\">this<\/span>.consumer?.stop({ <span class=\"hljs-attr\">abort<\/span>: <span class=\"hljs-literal\">true<\/span> });\n }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>3. Create the SQS controller:<\/strong><\/h5>\n\n\n\n<p>Create <code>sqs\/sqs.controller.ts <\/code>to send message to the SQS queue:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { Controller, Post, Body } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsProducerService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sqs.producer.service'<\/span>;\n\n@Controller(<span class=\"hljs-string\">'sqs'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SqsController<\/span> <\/span>{\n <span class=\"hljs-keyword\">constructor<\/span>(private sqsProducerService: SqsProducerService) {}\n\n@Post(<span class=\"hljs-string\">'publish'<\/span>)\n <span class=\"hljs-keyword\">async<\/span> publishMessage(@Body() body: { <span class=\"hljs-attr\">message<\/span>: string }) {\n  <span class=\"hljs-keyword\">const<\/span> { message } = body;\n  <span class=\"hljs-keyword\">const<\/span> messageResponse = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.sqsProducerService.sendMessage(message);\n  <span class=\"hljs-keyword\">return<\/span>{\n   <span class=\"hljs-attr\">status<\/span>: <span class=\"hljs-string\">'Message published'<\/span>,\n   message,\n   <span class=\"hljs-attr\">messageId<\/span>: messageResponse.MessageId,\n  };\n }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>4. Create the SQS Module to manage SQS services:<\/strong><\/h5>\n\n\n\n<p>Create <code>sqs\/sqs.module.ts<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { Module } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsProducerService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sqs.producer.service'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsConsumerService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sqs.consumer.service'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsController } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sqs.controller'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsMessageDao } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/daos\/sqs-message.dao'<\/span>;\n\n@Module({\n <span class=\"hljs-attr\">imports<\/span>: &#091;],\n <span class=\"hljs-attr\">controllers<\/span>: &#091;SqsController],\n <span class=\"hljs-attr\">providers<\/span>: &#091;SqsProducerService, SqsConsumerService, SqsMessageDao],\n <span class=\"hljs-attr\">exports<\/span>: &#091;SqsProducerService, SqsConsumerService],\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SqsModule<\/span> <\/span>{}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 8. Implement SNS in NestJS<\/strong><\/h4>\n\n\n\n<h5 class=\"font-change\"><strong>1. Create the SNS Publisher Service:<\/strong><\/h5>\n\n\n\n<p>Create <code>sns\/sns.publisher.service.ts<\/code> to send notification messages:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { PublishCommand, SNSClient } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@aws-sdk\/client-sns'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { Injectable } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { ConfigService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/config'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { v4 <span class=\"hljs-keyword\">as<\/span> uuid } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'uuid'<\/span>;\n\n@Injectable()\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SnsPublisherService<\/span> <\/span>{\n private snsClient: SNSClient;\n private topicArn: string;\n\n <span class=\"hljs-keyword\">constructor<\/span>(private configService: ConfigService) {\n  <span class=\"hljs-keyword\">this<\/span>.snsClient = <span class=\"hljs-keyword\">new<\/span> SNSClient({\n   <span class=\"hljs-attr\">region<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_REGION'<\/span>),\n   <span class=\"hljs-attr\">credentials<\/span>: {\n    <span class=\"hljs-attr\">accessKeyId<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_ACCESS_KEY_ID'<\/span>),\n    <span class=\"hljs-attr\">secretAccessKey<\/span>: <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'AWS_SECRET_ACCESS_KEY'<\/span>),\n   },\n  });\n  <span class=\"hljs-keyword\">this<\/span>.topicArn = <span class=\"hljs-keyword\">this<\/span>.configService.get(<span class=\"hljs-string\">'SNS_TOPIC_ARN'<\/span>);\n}\n\n<span class=\"hljs-keyword\">async<\/span> publishMessage(message: string) {\n <span class=\"hljs-keyword\">try<\/span> {\n  <span class=\"hljs-keyword\">const<\/span> command = <span class=\"hljs-keyword\">new<\/span> PublishCommand({\n   <span class=\"hljs-attr\">TopicArn<\/span>: <span class=\"hljs-keyword\">this<\/span>.topicArn,\n   <span class=\"hljs-attr\">Message<\/span>: message,\n   <span class=\"hljs-attr\">MessageGroupId<\/span>: <span class=\"hljs-string\">'sns-message-group'<\/span>,\n   <span class=\"hljs-attr\">MessageDeduplicationId<\/span>: uuid(),\n  });\n\n  <span class=\"hljs-keyword\">const<\/span> response = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.snsClient.send(command);\n  <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'SNS message sent: '<\/span>, message);\n  <span class=\"hljs-keyword\">return<\/span> response;\n }<span class=\"hljs-keyword\">catch<\/span> (error) {\n   <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'Error'<\/span>, error);\n  }\n }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>2. Create the Create SNS Controller:<\/strong><\/h5>\n\n\n\n<p>Create <code>sns\/sns.controller.ts<\/code> to send message to the SNS topic:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { Controller, Post, Body } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SnsPublisherService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sns.publisher.service'<\/span>;\n\n@Controller(<span class=\"hljs-string\">'sns'<\/span>)\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SnsController<\/span> <\/span>{\n <span class=\"hljs-keyword\">constructor<\/span>(private snsService: SnsPublisherService) {}\n\n @Post(<span class=\"hljs-string\">'publish'<\/span>)\n <span class=\"hljs-keyword\">async<\/span> publishMessage(@Body() body: { <span class=\"hljs-attr\">message<\/span>: string }) {\n  <span class=\"hljs-keyword\">const<\/span> { message } = body;\n  <span class=\"hljs-keyword\">const<\/span> messageResponse = <span class=\"hljs-keyword\">await<\/span> <span class=\"hljs-keyword\">this<\/span>.snsService.publishMessage(message);\n  <span class=\"hljs-keyword\">return<\/span> {\n   <span class=\"hljs-attr\">status<\/span>: <span class=\"hljs-string\">'Message published'<\/span>,\n   message,\n   <span class=\"hljs-attr\">messageId<\/span>: messageResponse.MessageId,\n  };\n }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h5 class=\"font-change\"><strong>3. Create the SNS Module to manage SNS services:<\/strong><\/h5>\n\n\n\n<p>Create <code>sns\/sns.module.ts<\/code><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { Module } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SnsPublisherService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sns.publisher.service'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SnsController } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sns.controller'<\/span>;\n\n@Module({\n <span class=\"hljs-attr\">imports<\/span>: &#091;],\n <span class=\"hljs-attr\">controllers<\/span>: &#091;SnsController],\n <span class=\"hljs-attr\">providers<\/span>: &#091;SnsPublisherService],\n <span class=\"hljs-attr\">exports<\/span>: &#091;SnsPublisherService],\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">SnsModule<\/span> <\/span>{}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 9. Setup App module to use SQS and SNS module<\/strong><\/h4>\n\n\n\n<p>Update <code>app.module.ts<\/code> to use the SQS and SNS modules:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> { Module } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/common'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { AppController } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/app.controller'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { AppService } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/app.service'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SnsModule } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sns\/sns.module'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsModule } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sqs\/sqs.module'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { ConfigModule } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/config'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { TypeOrmModule } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@nestjs\/typeorm'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { SqsMessage } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/sqs\/models\/sqs-message'<\/span>;\n\n@Module({\n <span class=\"hljs-attr\">imports<\/span>: &#091;\n  TypeOrmModule.forRoot({\n   <span class=\"hljs-attr\">type<\/span>: <span class=\"hljs-string\">'sqlite'<\/span>,\n   <span class=\"hljs-attr\">database<\/span>: <span class=\"hljs-string\">'sqlite.db'<\/span>,\n   <span class=\"hljs-attr\">entities<\/span>: &#091;SqsMessage],\n   <span class=\"hljs-attr\">synchronize<\/span>: <span class=\"hljs-literal\">true<\/span>, <span class=\"hljs-comment\">\/\/ Automatically sync the database schema (disable in production)<\/span>\n  }),\n  TypeOrmModule.forFeature(&#091;SqsMessage]),\n  SnsModule,\n  SqsModule,\n  ConfigModule.forRoot({\n   <span class=\"hljs-attr\">isGlobal<\/span>: <span class=\"hljs-literal\">true<\/span>,\n  }),\n ],\n <span class=\"hljs-attr\">controllers<\/span>: &#091;AppController],\n <span class=\"hljs-attr\">providers<\/span>: &#091;AppService],\n})\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">AppModule<\/span> <\/span>{}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 10: Run and Test the Application<\/strong><\/h4>\n\n\n\n<h5 class=\"font-change-color\">1. Start the application using <code>npm start<\/code>.<\/h5>\n\n\n\n<h5 class=\"font-change-color\">2. Send a POST request to <code>http:\/\/localhost:3000\/sns\/publish<\/code> with the body:<\/h5>\n\n\n\n<p>{ &#8220;message&#8221;: &#8220;Test Order Created&#8221; }<br>Check the response, it should confirm that the message was published.<br>You will also see the logs:<br><code>SNS message sent: Test Order Created<\/code><br><code>Received new message: Message object<\/code><\/p>\n\n\n\n<h5 class=\"font-change-color\">3. Send a POST request to <code>http:\/\/localhost:3000\/sqs\/publish<\/code> with the body:<\/h5>\n\n\n\n<p>{ &#8220;message&#8221;: &#8220;SQS Test Order Created&#8221; }<br>Check the response, it should confirm that the message was published.<br>You will also see the logs:<br><code>SQS message sent: SQS Test Order Created<\/code><br><code>Received new message: SQS Test Order Created<\/code><\/p>\n\n\n\n<h5 class=\"font-change-color\">You can find the complete AWS SQS and SNS integration codebase for NestJS on our <a href=\"https:\/\/github.com\/mobisoftinfotech\/aws-sqs-sns-node-js-tutorial\">Github<\/a><\/h5>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>In this blog, you\u2019ve explored how AWS SQS and SNS are integral to <a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/understanding-microservices-human-guide\"><strong>microservices architecture<\/strong><\/a>, facilitating scalable and efficient message handling. By following the step-by-step guide, you\u2019ve successfully configured SNS fanout and SQS subscriptions within a NestJS application using TypeScript. These integrations enable seamless communication between microservices, ensuring reliable message processing and event-driven architecture. With this knowledge, you can build robust, distributed systems capable of handling real-time data and notifications effectively.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mobisoftinfotech.com\/contact-us?utm_source=blog_cta&#038;utm_campaign=aws-sqs-sns-nestjs-typescript-tutorial-cta2\"><noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/master-nestjs-aws-sqs-sns.png\" alt=\"Master NestJS with AWS SQS and SNS for better messaging\" class=\"wp-image-34853\" title=\"Master NestJS with AWS SQS &amp; SNS for Enhanced Messaging\"><\/noscript><img decoding=\"async\" width=\"855\" height=\"150\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20855%20150%22%3E%3C%2Fsvg%3E\" alt=\"Master NestJS with AWS SQS and SNS for better messaging\" class=\"wp-image-34853 lazyload\" title=\"Master NestJS with AWS SQS &amp; SNS for Enhanced Messaging\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/master-nestjs-aws-sqs-sns.png\"><\/a><\/figure>\n\n\n<div class=\"related-posts-section\"><h2>Related Posts<\/h2><ul class=\"related-posts-list\"><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/vehicle-number-plate-detection-mechanism-using-computer-vision\">An Understanding of Vehicle Number Plate Detection Mechanism using Computer Vision<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/microinteractions-ui-ux-design-trends-examples\">Microinteractions in UI\/UX Design: Trends, Examples &amp; Best Practices<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/digital-twin-technology-impacting-automotive-industry\">How is Digital Twin Technology Impacting the Automotive Industry?<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/low-code-development-guide\">A Must-follow Guide to Low-Code Development in 2024<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/apples-healthkit-centralized-hub-for-health-data\">Apple\u2019s HealthKit: Centralized Hub for Health Data<\/a><\/li><li><a href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/nutritional-counseling-meal-benefits\">Nutritional Counseling and Meal Benefits Helping MA Plan Members Stay Healthy during COVID-19<\/a><\/li><\/ul><\/div>\n\n\n<div class=\"modern-author-card\">\n    <div class=\"author-card-content\">\n        <div class=\"author-info-section\">\n            <div class=\"author-avatar\">\n                <noscript><img decoding=\"async\" src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/Chetan_Shelake.jpg\" alt=\"Chetan Shelake\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"Chetan Shelake\" data-src=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/Chetan_Shelake.jpg\" class=\" lazyload\">\n            <\/div>\n            <div class=\"author-details\">\n                <h3 class=\"author-name\">Chetan Shelake<\/h3>\n                <p class=\"author-title\">Principal Software Engineer<\/p>\n                <a href=\"javascript:void(0);\" class=\"read-more-link read-more-btn\" onclick=\"toggleAuthorBio(this); return false;\">Read more <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"expand\" class=\"read-more-arrow down-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"expand\" class=\"read-more-arrow down-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <div class=\"author-bio-expanded\">\n                    <p>Chetan Shelake is a Principal Software Engineer at <a href=\"https:\/\/mobisoftinfotech.com\" target=\"_blank\" rel=\"nofollow noopener\">Mobisoft Infotech<\/a> with 7.5 years of experience in web, mobile, and backend development. Specializing in React, React Native, and Node, he is dedicated to building innovative and user-friendly applications. Chetan is passionate about delivering scalable solutions and staying ahead in emerging technologies.<\/p>\n                    \n                    <a href=\"javascript:void(0);\" class=\"read-more-link read-less-btn\" onclick=\"toggleAuthorBio(this); return false;\" style=\"display: none;\">Read less <noscript><img decoding=\"async\" src=\"\/assets\/images\/blog\/Vector.png\" alt=\"collapse\" class=\"read-more-arrow up-arrow\"><\/noscript><img decoding=\"async\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"collapse\" class=\"read-more-arrow up-arrow lazyload\" data-src=\"\/assets\/images\/blog\/Vector.png\"><\/a>\n                <\/div>\n            <\/div>\n        <\/div>\n        <div class=\"share-section\">\n            <span class=\"share-label\">Share Article<\/span>\n            <div class=\"social-share-buttons\">\n                <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Faws-sqs-sns-nestjs-typescript-tutorial\" target=\"_blank\" class=\"share-btn facebook-share\"><i class=\"fa fa-facebook-f\"><\/i><\/a>\n                <a href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=https%3A%2F%2Fmobisoftinfotech.com%2Fresources%2Fblog%2Faws-sqs-sns-nestjs-typescript-tutorial\" target=\"_blank\" class=\"share-btn linkedin-share\"><i class=\"fa fa-linkedin\"><\/i><\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Article\",\n  \"mainEntityOfPage\": {\n    \"@type\": \"WebPage\",\n    \"@id\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript\"\n  },\n  \"headline\": \"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript\",\n  \"description\": \"Learn how to integrate Shadcn UI with React 19 in this easy step-by-step tutorial. Enhance your React apps with modern, responsive UI components.\",\n  \"image\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png\",\n  \"author\": {\n    \"@type\": \"Person\",\n    \"name\": \"Chetan Shelake \",\n    \"description\": \"Chetan Shelake is a Principal Software Engineer at Mobisoft Infotech with 7.5 years of experience in web, mobile, and backend development. Specializing in React, React Native, and Node, he is dedicated to building innovative and user-friendly applications. Chetan is passionate about delivering scalable solutions and staying ahead in emerging technologies.\"\n  },\n  \"publisher\": {\n    \"@type\": \"Organization\",\n    \"name\": \"Mobisoft Infotech\",\n    \"logo\": {\n      \"@type\": \"ImageObject\",\n      \"url\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/mshomepage\/MI_Logo-white.svg\",\n      \"width\": 600,\n      \"height\": 60\n    }\n  },\n  \"datePublished\": \"2025-01-28\",\n  \"dateModified\": \"2025-01-28\"\n}\n<\/script>\n<script type=\"application\/ld+json\">\n{\n  \"@context\": \"https:\/\/schema.org\",\n  \"@type\": \"Organization\",\n  \"name\": \"Mobisoft Infotech\",\n  \"url\": \"https:\/\/mobisoftinfotech.com\/\",\n  \"logo\": \"https:\/\/mobisoftinfotech.com\/assets\/images\/MI_Logo.svg\",\n  \"sameAs\": [\n    \"https:\/\/www.facebook.com\/pages\/Mobisoft-Infotech\/131035500270720\",\n    \"https:\/\/twitter.com\/MobisoftInfo\",\n    \"https:\/\/www.instagram.com\/mobisoftinfotech\/\",\n    \"https:\/\/www.youtube.com\/channel\/UCtwuTXKUXFX7k0NSYhsMeTg\",\n    \"https:\/\/www.linkedin.com\/company\/mobisoft-infotech\",\n    \"https:\/\/in.pinterest.com\/mobisoftinfotech\/\",\n    \"https:\/\/github.com\/MobisoftInfotech\"\n  ],\n  \"contactPoint\": [\n    {\n      \"@type\": \"ContactPoint\",\n      \"telephone\": \"+1-855-572-2777\",\n      \"contactType\": \"Customer Service\",\n      \"areaServed\": \"US\",\n      \"availableLanguage\": [\"English\"]\n    },\n    {\n      \"@type\": \"ContactPoint\",\n      \"telephone\": \"+91-858-600-8627\",\n      \"contactType\": \"Customer Service\",\n      \"areaServed\": \"IN\",\n      \"availableLanguage\": [\"English\"]\n    }\n  ]\n}\n<\/script>\n<script type=\"application\/ld+json\">\n    [\n    {\n        \"@context\": \"https:\/\/schema.org\",\n        \"@type\": \"ImageObject\",\n        \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png\",\n        \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\",\n        \"name\": \"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript\",\n        \"caption\": \" Learn how to set up the FortiGate firewall for a secure AWS connection.\",\n        \"description\": \"A step-by-step guide on setting up FortiGate firewall to secure your AWS environment and ensure seamless communication between AWS and your office network.\",\n        \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n        \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n        \"creditText\": \"Mobisoft Infotech\",\n        \"copyrightNotice\": \"Mobisoft Infotech\",\n        \"creator\": {\n            \"@type\": \"Organization\",\n            \"name\": \"Mobisoft Infotech\"\n        },\n        \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png\"\n    },\n    {\n        \"@context\": \"https:\/\/schema.org\",\n        \"@type\": \"ImageObject\",\n        \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/sns-fanout-pattern-event-driven-architecture.png\",\n        \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\",\n        \"name\": \"SNS Fanout Pattern for Event-Driven Architecture in AWS\",\n        \"caption\": \"Understanding the SNS Fanout Pattern to enhance event-driven architecture in AWS with NestJS and TypeScript.\",\n        \"description\": \"Learn how the SNS Fanout Pattern facilitates message distribution across multiple services in AWS, optimizing your event-driven architecture within a NestJS application using TypeScript.\",\n        \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n        \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n        \"creditText\": \"Mobisoft Infotech\",\n        \"copyrightNotice\": \"Mobisoft Infotech\",\n        \"creator\": {\n            \"@type\": \"Organization\",\n            \"name\": \"Mobisoft Infotech\"\n        },\n        \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/sns-fanout-pattern-event-driven-architecture.png\"\n    },\n    {\n        \"@context\": \"https:\/\/schema.org\",\n        \"@type\": \"ImageObject\",\n        \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/master-nestjs-aws-sqs-sns.png\",\n        \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\",\n        \"name\": \"Master NestJS with AWS SQS & SNS for Enhanced Messaging\",\n        \"caption\": \"Unlock the full potential of NestJS by mastering AWS SQS and SNS for asynchronous messaging and event-driven systems with TypeScript\",\n        \"description\": \"Elevate your NestJS skills by integrating AWS SQS and SNS, ensuring your application is optimized for scalable, asynchronous messaging in event-driven architectures.\",\n        \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n        \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n        \"creditText\": \"Mobisoft Infotech\",\n        \"copyrightNotice\": \"Mobisoft Infotech\",\n        \"creator\": {\n            \"@type\": \"Organization\",\n            \"name\": \"Mobisoft Infotech\"\n        },\n        \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/master-nestjs-aws-sqs-sns.png\"\n    },\n    {\n        \"@context\": \"https:\/\/schema.org\",\n        \"@type\": \"ImageObject\",\n        \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/start-building-aws-sqs-sns-nestjs.png\",\n        \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\",\n        \"name\": \"Start Building with AWS SQS & SNS in NestJS Today\",\n        \"caption\": \"Kickstart your journey with AWS SQS and SNS by building a NestJS application using TypeScript for scalable and efficient messaging.\",\n        \"description\": \"Begin your project with AWS SQS and SNS in NestJS, leveraging TypeScript to build high-performance, event-driven systems.\",\n        \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n        \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n        \"creditText\": \"Mobisoft Infotech\",\n        \"copyrightNotice\": \"Mobisoft Infotech\",\n        \"creator\": {\n            \"@type\": \"Organization\",\n            \"name\": \"Mobisoft Infotech\"\n        },\n        \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/start-building-aws-sqs-sns-nestjs.png\"\n    },\n    {\n        \"@context\": \"https:\/\/schema.org\",\n        \"@type\": \"ImageObject\",\n        \"contentUrl\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/aws-nestjs-integration-logo.png\",\n        \"url\": \"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\",\n        \"name\": \"AWS and NestJS Integration for Scalable Applications\",\n        \"caption\": \"Integrating AWS SQS and SNS with NestJS for scalable, event-driven applications using TypeScript.\",\n        \"description\": \"The AWS and NestJS integration empowers developers to build scalable, asynchronous applications using AWS SQS and SNS for messaging and event-driven patterns.\",\n        \"license\": \"https:\/\/mobisoftinfotech.com\/terms\",\n        \"acquireLicensePage\": \"https:\/\/mobisoftinfotech.com\/acquire-license\",\n        \"creditText\": \"Mobisoft Infotech\",\n        \"copyrightNotice\": \"Mobisoft Infotech\",\n        \"creator\": {\n            \"@type\": \"Organization\",\n            \"name\": \"Mobisoft Infotech\"\n        },\n        \"thumbnail\": \"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/aws-nestjs-integration-logo.png\"\n    }\n    ]\n<\/script>\n<style>\n@media only screen and (max-width:767px){.post-content li:before {\n    content: '';\n    width: 9px;\n    height: 9px;\n    background-color: #0d265c;\n    border-radius: 50%;\n    position: absolute;\n    left: 0px;\n    top: 12px;\n}\n.post-content li {\n    padding-left: 25px;\n}\n.post-content p, .post-content li{text-align: left;}}\n.font-change{\nfont-size:22px !important;\n}\n.font-change-color{\nfont-size:22px !important;\n\nfont-weight: 700 !important;\n}\n \n \n<\/style>\n\n\n","protected":false},"excerpt":{"rendered":"<p>In microservices architectures, AWS SQS and SNS are essential services for connecting and managing communication between distributed systems. In this blog post, we will guide you through setting up AWS SQS and AWS SNS in a NestJS project using TypeScript. You\u2019ll also learn how to use the SNS fan-out pattern to broadcast messages and subscribe [&hellip;]<\/p>\n","protected":false},"author":95,"featured_media":34842,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[286],"tags":[4636,4639,4635,4640,4642,4643,4641,4637,4638,4644],"class_list":["post-34835","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-aws-sns-tutorial","tag-aws-sqs-and-sns","tag-aws-sqs-tutorial","tag-aws-sqs-typescript","tag-event-driven-architecture-aws","tag-nestjs-asynchronous-messaging","tag-nestjs-aws-example","tag-nestjs-tutorial","tag-typescript-aws-integration","tag-typescript-message-queue"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AWS SQS &amp; SNS in NestJS with TypeScript Tutorial<\/title>\n<meta name=\"description\" content=\"Learn how to integrate AWS SQS &amp; SNS with NestJS using TypeScript for scalable event-driven architectures and asynchronous messaging.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AWS SQS &amp; SNS in NestJS with TypeScript Tutorial\" \/>\n<meta property=\"og:description\" content=\"Learn how to integrate AWS SQS &amp; SNS with NestJS using TypeScript for scalable event-driven architectures and asynchronous messaging.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\" \/>\n<meta property=\"og:site_name\" content=\"Mobisoft Infotech\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-28T13:31:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-05T09:51:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/og-How-to-Use-AWS-SQS-SNS-in-NestJS-with-TypeScript.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"525\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Chetan Shelake\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chetan Shelake\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#article\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\"},\"author\":{\"name\":\"Chetan Shelake\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/b687ac0452e66fa531e251ea15299662\"},\"headline\":\"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript\",\"datePublished\":\"2025-01-28T13:31:37+00:00\",\"dateModified\":\"2026-01-05T09:51:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\"},\"wordCount\":836,\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png\",\"keywords\":[\"AWS SNS tutorial\",\"AWS SQS and SNS\",\"AWS SQS tutorial\",\"AWS SQS TypeScript\",\"Event-driven architecture AWS\",\"NestJS asynchronous messaging\",\"NestJS AWS example\",\"NestJS tutorial\",\"TypeScript AWS integration\",\"TypeScript message queue\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\",\"name\":\"AWS SQS & SNS in NestJS with TypeScript Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage\"},\"image\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage\"},\"thumbnailUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png\",\"datePublished\":\"2025-01-28T13:31:37+00:00\",\"dateModified\":\"2026-01-05T09:51:51+00:00\",\"author\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/b687ac0452e66fa531e251ea15299662\"},\"description\":\"Learn how to integrate AWS SQS & SNS with NestJS using TypeScript for scalable event-driven architectures and asynchronous messaging.\",\"breadcrumb\":{\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png\",\"contentUrl\":\"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png\",\"width\":855,\"height\":392,\"caption\":\"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mobisoftinfotech.com\/resources\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#website\",\"url\":\"https:\/\/mobisoftinfotech.com\/resources\/\",\"name\":\"Mobisoft Infotech\",\"description\":\"Discover Mobility\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/b687ac0452e66fa531e251ea15299662\",\"name\":\"Chetan Shelake\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/d00da0aa6e84627bbe1e8018c969afb8cc152be94eff76a32f342bde203c0e7f?s=96&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d00da0aa6e84627bbe1e8018c969afb8cc152be94eff76a32f342bde203c0e7f?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d00da0aa6e84627bbe1e8018c969afb8cc152be94eff76a32f342bde203c0e7f?s=96&r=g\",\"caption\":\"Chetan Shelake\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AWS SQS & SNS in NestJS with TypeScript Tutorial","description":"Learn how to integrate AWS SQS & SNS with NestJS using TypeScript for scalable event-driven architectures and asynchronous messaging.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial","og_locale":"en_US","og_type":"article","og_title":"AWS SQS & SNS in NestJS with TypeScript Tutorial","og_description":"Learn how to integrate AWS SQS & SNS with NestJS using TypeScript for scalable event-driven architectures and asynchronous messaging.","og_url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial","og_site_name":"Mobisoft Infotech","article_published_time":"2025-01-28T13:31:37+00:00","article_modified_time":"2026-01-05T09:51:51+00:00","og_image":[{"width":1000,"height":525,"url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/og-How-to-Use-AWS-SQS-SNS-in-NestJS-with-TypeScript.png","type":"image\/png"}],"author":"Chetan Shelake","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Chetan Shelake","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#article","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial"},"author":{"name":"Chetan Shelake","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/b687ac0452e66fa531e251ea15299662"},"headline":"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript","datePublished":"2025-01-28T13:31:37+00:00","dateModified":"2026-01-05T09:51:51+00:00","mainEntityOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial"},"wordCount":836,"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png","keywords":["AWS SNS tutorial","AWS SQS and SNS","AWS SQS tutorial","AWS SQS TypeScript","Event-driven architecture AWS","NestJS asynchronous messaging","NestJS AWS example","NestJS tutorial","TypeScript AWS integration","TypeScript message queue"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial","url":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial","name":"AWS SQS & SNS in NestJS with TypeScript Tutorial","isPartOf":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage"},"image":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage"},"thumbnailUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png","datePublished":"2025-01-28T13:31:37+00:00","dateModified":"2026-01-05T09:51:51+00:00","author":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/b687ac0452e66fa531e251ea15299662"},"description":"Learn how to integrate AWS SQS & SNS with NestJS using TypeScript for scalable event-driven architectures and asynchronous messaging.","breadcrumb":{"@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#primaryimage","url":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png","contentUrl":"https:\/\/mobisoftinfotech.com\/resources\/wp-content\/uploads\/2025\/01\/use-aws-sqs-sns-in-nestjs-typescript.png","width":855,"height":392,"caption":"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript"},{"@type":"BreadcrumbList","@id":"https:\/\/mobisoftinfotech.com\/resources\/blog\/aws-sqs-sns-nestjs-typescript-tutorial#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mobisoftinfotech.com\/resources\/"},{"@type":"ListItem","position":2,"name":"AWS SQS and SNS Node JS tutorial: Integrating AWS SQS and SNS in a NestJS Application with TypeScript"}]},{"@type":"WebSite","@id":"https:\/\/mobisoftinfotech.com\/resources\/#website","url":"https:\/\/mobisoftinfotech.com\/resources\/","name":"Mobisoft Infotech","description":"Discover Mobility","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mobisoftinfotech.com\/resources\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/mobisoftinfotech.com\/resources\/#\/schema\/person\/b687ac0452e66fa531e251ea15299662","name":"Chetan Shelake","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d00da0aa6e84627bbe1e8018c969afb8cc152be94eff76a32f342bde203c0e7f?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d00da0aa6e84627bbe1e8018c969afb8cc152be94eff76a32f342bde203c0e7f?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d00da0aa6e84627bbe1e8018c969afb8cc152be94eff76a32f342bde203c0e7f?s=96&r=g","caption":"Chetan Shelake"}}]}},"_links":{"self":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/34835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/users\/95"}],"replies":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/comments?post=34835"}],"version-history":[{"count":144,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/34835\/revisions"}],"predecessor-version":[{"id":46352,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/posts\/34835\/revisions\/46352"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media\/34842"}],"wp:attachment":[{"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/media?parent=34835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/categories?post=34835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mobisoftinfotech.com\/resources\/wp-json\/wp\/v2\/tags?post=34835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}