or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

batch-operations.mdclient-configuration.mddead-letter-queues.mdindex.mdmessage-move-tasks.mdmessage-operations.mdqueue-attributes-tags.mdqueue-management.mdqueue-permissions.md
tile.json

index.mddocs/

AWS SDK SQS Client

AWS SDK for JavaScript SQS Client provides comprehensive access to Amazon Simple Queue Service (SQS) for Node.js, Browser and React Native applications. It offers a modern, promise-based API for all SQS operations including message sending/receiving, queue management, batch operations, and advanced features like dead letter queues and message move tasks.

Package Information

  • Package Name: @aws-sdk/client-sqs
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @aws-sdk/client-sqs

Core Imports

import { SQSClient, SendMessageCommand, ReceiveMessageCommand } from "@aws-sdk/client-sqs";

For CommonJS:

const { SQSClient, SendMessageCommand, ReceiveMessageCommand } = require("@aws-sdk/client-sqs");

V2 Compatible (larger bundle):

import * as AWS from "@aws-sdk/client-sqs";
const client = new AWS.SQS({ region: "us-east-1" });

Basic Usage

import { SQSClient, SendMessageCommand, ReceiveMessageCommand } from "@aws-sdk/client-sqs";

// Initialize client
const client = new SQSClient({ region: "us-east-1" });

// Send a message
const sendResult = await client.send(new SendMessageCommand({
  QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
  MessageBody: "Hello, SQS!",
  MessageAttributes: {
    Author: {
      StringValue: "myapp",
      DataType: "String"
    }
  }
}));

// Receive messages
const receiveResult = await client.send(new ReceiveMessageCommand({
  QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
  MaxNumberOfMessages: 10,
  WaitTimeSeconds: 20
}));

// Process received messages
for (const message of receiveResult.Messages || []) {
  console.log("Message:", message.Body);
  
  // Delete message after processing
  await client.send(new DeleteMessageCommand({
    QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
    ReceiptHandle: message.ReceiptHandle
  }));
}

Architecture

The AWS SQS Client is built around several key components:

  • Command Pattern: All operations use command objects (SendMessageCommand, ReceiveMessageCommand, etc.)
  • Client Classes: SQSClient for modern v3 API, SQS for v2-compatible interface
  • Middleware Stack: Extensible middleware for authentication, retry logic, logging, and custom processing
  • Type Safety: Full TypeScript support with generic types and interfaces
  • Error Handling: Comprehensive exception hierarchy with detailed error information
  • Platform Support: Universal compatibility across Node.js, browsers, and React Native

Capabilities

Client Configuration

Core client setup and configuration options for authentication, regions, and custom settings.

class SQSClient {
  constructor(configuration: SQSClientConfig);
  send<InputType, OutputType>(
    command: Command<InputType, OutputType, SQSClientResolvedConfig>
  ): Promise<OutputType>;
  destroy(): void;
}

interface SQSClientConfig {
  region?: string | Provider<string>;
  credentials?: AwsCredentialIdentityProvider;
  endpoint?: string | Endpoint | Provider<Endpoint>;
  logger?: Logger;
  retryMode?: string | Provider<RetryMode>;
  maxAttempts?: number | Provider<number>;
}

Client Configuration

Queue Management

Complete queue lifecycle operations including creation, deletion, attribute management, and URL resolution.

class CreateQueueCommand {
  constructor(input: CreateQueueCommandInput);
}

interface CreateQueueCommandInput {
  QueueName: string;
  Attributes?: Record<QueueAttributeName, string>;
  tags?: Record<string, string>;
}

class DeleteQueueCommand {
  constructor(input: DeleteQueueCommandInput);
}

interface DeleteQueueCommandInput {
  QueueUrl: string;
}

Queue Management

Message Operations

Core messaging functionality for sending, receiving, and deleting messages with full support for message attributes and batch operations.

class SendMessageCommand {
  constructor(input: SendMessageCommandInput);
}

interface SendMessageCommandInput {
  QueueUrl: string;
  MessageBody: string;
  DelaySeconds?: number;
  MessageAttributes?: Record<string, MessageAttributeValue>;
  MessageDeduplicationId?: string;
  MessageGroupId?: string;
}

class ReceiveMessageCommand {
  constructor(input: ReceiveMessageCommandInput);
}

interface ReceiveMessageCommandInput {
  QueueUrl: string;
  AttributeNames?: QueueAttributeName[];
  MessageAttributeNames?: string[];
  MaxNumberOfMessages?: number;
  VisibilityTimeoutSeconds?: number;
  WaitTimeSeconds?: number;
}

Message Operations

Batch Operations

High-performance batch operations for sending, deleting, and changing visibility of multiple messages in single API calls.

class SendMessageBatchCommand {
  constructor(input: SendMessageBatchCommandInput);
}

interface SendMessageBatchCommandInput {
  QueueUrl: string;
  Entries: SendMessageBatchRequestEntry[];
}

interface SendMessageBatchRequestEntry {
  Id: string;
  MessageBody: string;
  DelaySeconds?: number;
  MessageAttributes?: Record<string, MessageAttributeValue>;
}

Batch Operations

Queue Permissions

Access control management for SQS queues including adding and removing permissions for cross-account access.

class AddPermissionCommand {
  constructor(input: AddPermissionCommandInput);
}

interface AddPermissionCommandInput {
  QueueUrl: string;
  Label: string;
  AWSAccountIds: string[];
  Actions: string[];
}

Queue Permissions

Queue Attributes and Tags

Queue configuration management through attributes and metadata management through tags.

class SetQueueAttributesCommand {
  constructor(input: SetQueueAttributesCommandInput);
}

interface SetQueueAttributesCommandInput {
  QueueUrl: string;
  Attributes: Record<QueueAttributeName, string>;
}

class TagQueueCommand {
  constructor(input: TagQueueCommandInput);
}

interface TagQueueCommandInput {
  QueueUrl: string;
  Tags: Record<string, string>;
}

Queue Attributes and Tags

Dead Letter Queues

Advanced queue management for handling failed messages with dead letter queue configuration and source queue discovery.

class ListDeadLetterSourceQueuesCommand {
  constructor(input: ListDeadLetterSourceQueuesCommandInput);
}

interface ListDeadLetterSourceQueuesCommandInput {
  QueueUrl: string;
  NextToken?: string;
  MaxResults?: number;
}

Dead Letter Queues

Message Move Tasks

Advanced message management for moving messages between queues with progress tracking and cancellation support.

class StartMessageMoveTaskCommand {
  constructor(input: StartMessageMoveTaskCommandInput);
}

interface StartMessageMoveTaskCommandInput {
  SourceArn: string;
  DestinationArn?: string;
  MaxNumberOfMessagesPerSecond?: number;
}

Message Move Tasks

Core Types

interface Message {
  MessageId?: string;
  ReceiptHandle?: string;
  MD5OfBody?: string;
  Body?: string;
  Attributes?: Record<MessageSystemAttributeName, string>;
  MD5OfMessageAttributes?: string;
  MessageAttributes?: Record<string, MessageAttributeValue>;
}

interface MessageAttributeValue {
  StringValue?: string;
  BinaryValue?: Uint8Array;
  StringListValues?: string[];
  BinaryListValues?: Uint8Array[];
  DataType: string;
}

enum QueueAttributeName {
  All = "All",
  Policy = "Policy",
  VisibilityTimeout = "VisibilityTimeout",
  MaxReceiveCount = "MaxReceiveCount",
  MessageRetentionPeriod = "MessageRetentionPeriod",
  ApproximateNumberOfMessages = "ApproximateNumberOfMessages",
  ApproximateNumberOfMessagesNotVisible = "ApproximateNumberOfMessagesNotVisible",
  CreatedTimestamp = "CreatedTimestamp",
  LastModifiedTimestamp = "LastModifiedTimestamp",
  QueueArn = "QueueArn",
  ApproximateNumberOfMessagesDelayed = "ApproximateNumberOfMessagesDelayed",
  DelaySeconds = "DelaySeconds",
  ReceiveMessageWaitTimeSeconds = "ReceiveMessageWaitTimeSeconds",
  RedrivePolicy = "RedrivePolicy",
  FifoQueue = "FifoQueue",
  ContentBasedDeduplication = "ContentBasedDeduplication",
  KmsMasterKeyId = "KmsMasterKeyId",
  KmsDataKeyReusePeriodSeconds = "KmsDataKeyReusePeriodSeconds",
  DeduplicationScope = "DeduplicationScope",
  FifoThroughputLimit = "FifoThroughputLimit",
  RedriveAllowPolicy = "RedriveAllowPolicy",
  SqsManagedSseEnabled = "SqsManagedSseEnabled"
}

Error Handling

All SQS operations can throw service exceptions that extend SQSServiceException. Common exceptions include:

  • QueueDoesNotExist - Queue URL incorrect or queue deleted
  • InvalidAddress - Invalid ID specified
  • OverLimit - Action violates service limits
  • RequestThrottled - Request rate exceeded limits
  • InvalidSecurity - Request not over HTTPS or missing SigV4
  • MessageNotInflight - Message not available for visibility change
  • ReceiptHandleIsInvalid - Receipt handle invalid or expired
try {
  await client.send(command);
} catch (error) {
  if (error.name === 'QueueDoesNotExist') {
    console.error('Queue not found:', error.message);
  } else if (error.name === 'RequestThrottled') {
    console.error('Rate limit exceeded:', error.message);
  }
  
  // Access metadata
  console.log('Request ID:', error.$metadata?.requestId);
}