Client setup and configuration options for AWS SQS including authentication, regions, endpoints, and middleware configuration.
Main client class for AWS SQS operations with full configuration support.
/**
* AWS SQS client providing access to Amazon Simple Queue Service
*/
class SQSClient {
/**
* Create new SQS client instance
* @param configuration - Client configuration options
*/
constructor(configuration: SQSClientConfig);
/**
* Send command to SQS service
* @param command - SQS command to execute
* @returns Promise resolving to command output
*/
send<InputType, OutputType>(
command: Command<InputType, OutputType, SQSClientResolvedConfig>
): Promise<OutputType>;
/**
* Clean up client resources and close connections
*/
destroy(): void;
}
interface SQSClientConfig {
/** AWS region for SQS operations */
region?: string | Provider<string>;
/** AWS credentials for authentication */
credentials?: AwsCredentialIdentityProvider;
/** Custom endpoint URL or configuration */
endpoint?: string | Endpoint | Provider<Endpoint>;
/** Custom logger for request/response logging */
logger?: Logger;
/** Retry strategy configuration */
retryMode?: string | Provider<RetryMode>;
/** Maximum number of retry attempts */
maxAttempts?: number | Provider<number>;
/** Custom HTTP handler for requests */
requestHandler?: RequestHandler;
/** Request timeout in milliseconds */
requestTimeout?: number;
/** Custom user agent string */
customUserAgent?: string;
}Aggregated client providing direct method access for backward compatibility.
/**
* V2-compatible SQS client with direct method calls
*/
class SQS {
constructor(configuration: SQSClientConfig);
/** Send message using direct method call */
sendMessage(params: SendMessageRequest): Promise<SendMessageResult>;
/** Receive messages using direct method call */
receiveMessage(params: ReceiveMessageRequest): Promise<ReceiveMessageResult>;
/** Delete message using direct method call */
deleteMessage(params: DeleteMessageRequest): Promise<void>;
/** Create queue using direct method call */
createQueue(params: CreateQueueRequest): Promise<CreateQueueResult>;
/** Delete queue using direct method call */
deleteQueue(params: DeleteQueueRequest): Promise<void>;
/** List queues using direct method call */
listQueues(params?: ListQueuesRequest): Promise<ListQueuesResult>;
}Usage Examples:
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
// Basic client with region
const client = new SQSClient({
region: "us-east-1"
});
// Client with custom credentials
const clientWithCreds = new SQSClient({
region: "us-west-2",
credentials: {
accessKeyId: "your-access-key",
secretAccessKey: "your-secret-key"
}
});
// Client with custom endpoint (for LocalStack)
const localClient = new SQSClient({
region: "us-east-1",
endpoint: "http://localhost:4566"
});
// Client with retry configuration
const resilientClient = new SQSClient({
region: "us-east-1",
retryMode: "adaptive",
maxAttempts: 5
});
// V2 compatible usage
import * as AWS from "@aws-sdk/client-sqs";
const v2Client = new AWS.SQS({ region: "us-east-1" });
const result = await v2Client.sendMessage({
QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
MessageBody: "Hello World"
});Core configuration interfaces and types for client setup.
interface Endpoint {
protocol?: string;
hostname?: string;
port?: number;
path?: string;
}
interface Provider<T> {
(): Promise<T>;
}
interface AwsCredentialIdentityProvider extends Provider<AwsCredentialIdentity> {}
interface AwsCredentialIdentity {
accessKeyId: string;
secretAccessKey: string;
sessionToken?: string;
}
interface Logger {
trace?: (content: any) => void;
debug?: (content: any) => void;
info?: (content: any) => void;
warn?: (content: any) => void;
error?: (content: any) => void;
}
type RetryMode = "legacy" | "standard" | "adaptive";
interface RequestHandler {
handle(request: any, options?: any): Promise<any>;
}The client automatically uses the appropriate regional SQS endpoint based on the configured region. Standard AWS regions are supported:
us-east-1us-west-2eu-west-1ap-northeast-1For custom endpoints (like LocalStack or custom SQS implementations), use the endpoint configuration option.
The client supports multiple authentication methods:
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY~/.aws/credentialsClient configuration errors throw synchronous exceptions during construction, while service operation errors are returned as rejected promises.
try {
const client = new SQSClient({ region: "invalid-region" });
await client.send(command);
} catch (error) {
console.error("Operation failed:", error.message);
console.log("Request ID:", error.$metadata?.requestId);
}