AWS SDK for JavaScript SQS Client providing comprehensive access to Amazon Simple Queue Service for Node.js, Browser and React Native applications
—
Queue configuration management through attributes and metadata management through tags for organizing and monitoring SQS resources.
Modifies configuration attributes of an existing queue.
class SetQueueAttributesCommand {
constructor(input: SetQueueAttributesCommandInput);
}
interface SetQueueAttributesCommandInput {
/** URL of the queue to modify */
QueueUrl: string;
/** Attributes to set with their values */
Attributes: Record<QueueAttributeName, string>;
}Retrieves current attribute values for a queue.
class GetQueueAttributesCommand {
constructor(input: GetQueueAttributesCommandInput);
}
interface GetQueueAttributesCommandInput {
/** URL of the queue */
QueueUrl: string;
/** Attribute names to retrieve or 'All' for everything */
AttributeNames?: QueueAttributeName[];
}
interface GetQueueAttributesCommandOutput {
/** Map of attribute names to values */
Attributes?: Record<QueueAttributeName, string>;
}Usage Examples:
import { SQSClient, SetQueueAttributesCommand, GetQueueAttributesCommand } from "@aws-sdk/client-sqs";
const client = new SQSClient({ region: "us-east-1" });
// Configure queue timeouts and retention
await client.send(new SetQueueAttributesCommand({
QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
Attributes: {
VisibilityTimeoutSeconds: "120", // 2 minutes
MessageRetentionPeriod: "1209600", // 14 days
ReceiveMessageWaitTimeSeconds: "20", // Long polling
DelaySeconds: "0" // No delay
}
}));
// Configure dead letter queue
await client.send(new SetQueueAttributesCommand({
QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
Attributes: {
RedrivePolicy: JSON.stringify({
deadLetterTargetArn: "arn:aws:sqs:us-east-1:123456789012:MyQueue-DLQ",
maxReceiveCount: 3
})
}
}));
// Get current attributes
const attributes = await client.send(new GetQueueAttributesCommand({
QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
AttributeNames: ["All"]
}));
console.log("Queue ARN:", attributes.Attributes?.QueueArn);
console.log("Messages in queue:", attributes.Attributes?.ApproximateNumberOfMessages);Adds or updates tags on a queue for organization and billing.
class TagQueueCommand {
constructor(input: TagQueueCommandInput);
}
interface TagQueueCommandInput {
/** URL of the queue to tag */
QueueUrl: string;
/** Tags to add or update */
Tags: Record<string, string>;
}Removes specified tags from a queue.
class UntagQueueCommand {
constructor(input: UntagQueueCommandInput);
}
interface UntagQueueCommandInput {
/** URL of the queue */
QueueUrl: string;
/** Tag keys to remove */
TagKeys: string[];
}Retrieves all tags associated with a queue.
class ListQueueTagsCommand {
constructor(input: ListQueueTagsCommandInput);
}
interface ListQueueTagsCommandInput {
/** URL of the queue */
QueueUrl: string;
}
interface ListQueueTagsCommandOutput {
/** Map of tag keys to values */
Tags?: Record<string, string>;
}Usage Examples:
// Add tags for organization
await client.send(new TagQueueCommand({
QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue",
Tags: {
Environment: "production",
Application: "order-processing",
Team: "backend",
CostCenter: "engineering"
}
}));
// Update specific tags
await client.send(new TagQueueCommand({
QueueUrl: queueUrl,
Tags: {
Environment: "staging", // Updates existing tag
Version: "2.1" // Adds new tag
}
}));
// List current tags
const tags = await client.send(new ListQueueTagsCommand({
QueueUrl: queueUrl
}));
console.log("Queue tags:", tags.Tags);
// Remove tags
await client.send(new UntagQueueCommand({
QueueUrl: queueUrl,
TagKeys: ["Version", "OldTag"]
}));enum QueueAttributeName {
/** Get all attributes */
All = "All",
/** Queue access policy (JSON) */
Policy = "Policy",
/** Message visibility timeout in seconds (0-43200) */
VisibilityTimeout = "VisibilityTimeout",
/** Message retention period in seconds (60-1209600) */
MessageRetentionPeriod = "MessageRetentionPeriod",
/** Maximum message size in bytes (1024-262144) */
MaximumMessageSize = "MaximumMessageSize",
/** Approximate number of messages in queue */
ApproximateNumberOfMessages = "ApproximateNumberOfMessages",
/** Approximate number of messages not visible */
ApproximateNumberOfMessagesNotVisible = "ApproximateNumberOfMessagesNotVisible",
/** Queue creation timestamp */
CreatedTimestamp = "CreatedTimestamp",
/** Last modification timestamp */
LastModifiedTimestamp = "LastModifiedTimestamp",
/** Queue ARN */
QueueArn = "QueueArn",
/** Approximate number of delayed messages */
ApproximateNumberOfMessagesDelayed = "ApproximateNumberOfMessagesDelayed",
/** Default message delay in seconds (0-900) */
DelaySeconds = "DelaySeconds",
/** Long polling wait time in seconds (0-20) */
ReceiveMessageWaitTimeSeconds = "ReceiveMessageWaitTimeSeconds",
/** Dead letter queue configuration (JSON) */
RedrivePolicy = "RedrivePolicy",
/** Whether queue is FIFO */
FifoQueue = "FifoQueue",
/** Enable content-based deduplication for FIFO */
ContentBasedDeduplication = "ContentBasedDeduplication",
/** KMS master key ID for encryption */
KmsMasterKeyId = "KmsMasterKeyId",
/** KMS data key reuse period in seconds */
KmsDataKeyReusePeriodSeconds = "KmsDataKeyReusePeriodSeconds",
/** FIFO deduplication scope */
DeduplicationScope = "DeduplicationScope",
/** FIFO throughput limit */
FifoThroughputLimit = "FifoThroughputLimit",
/** Redrive allow policy (JSON) */
RedriveAllowPolicy = "RedriveAllowPolicy",
/** Enable SQS-managed server-side encryption */
SqsManagedSseEnabled = "SqsManagedSseEnabled"
}// Configure high-throughput FIFO queue
await client.send(new SetQueueAttributesCommand({
QueueUrl: "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue.fifo",
Attributes: {
FifoQueue: "true",
ContentBasedDeduplication: "true",
DeduplicationScope: "messageGroup",
FifoThroughputLimit: "perMessageGroupId"
}
}));// Enable KMS encryption
await client.send(new SetQueueAttributesCommand({
QueueUrl: queueUrl,
Attributes: {
KmsMasterKeyId: "alias/aws/sqs",
KmsDataKeyReusePeriodSeconds: "300"
}
}));
// Enable SQS-managed encryption
await client.send(new SetQueueAttributesCommand({
QueueUrl: queueUrl,
Attributes: {
SqsManagedSseEnabled: "true"
}
}));// Configure comprehensive DLQ policy
const redrivePolicy = {
deadLetterTargetArn: "arn:aws:sqs:us-east-1:123456789012:MyApp-DLQ",
maxReceiveCount: 3
};
await client.send(new SetQueueAttributesCommand({
QueueUrl: mainQueueUrl,
Attributes: {
RedrivePolicy: JSON.stringify(redrivePolicy),
MessageRetentionPeriod: "1209600" // 14 days
}
}));
// Configure redrive allow policy on DLQ
const redriveAllowPolicy = {
redrivePermission: "byQueue",
sourceQueueArns: ["arn:aws:sqs:us-east-1:123456789012:MyApp-Main"]
};
await client.send(new SetQueueAttributesCommand({
QueueUrl: dlqUrl,
Attributes: {
RedriveAllowPolicy: JSON.stringify(redriveAllowPolicy)
}
}));// Get key metrics for monitoring
const metrics = await client.send(new GetQueueAttributesCommand({
QueueUrl: queueUrl,
AttributeNames: [
"ApproximateNumberOfMessages",
"ApproximateNumberOfMessagesNotVisible",
"ApproximateNumberOfMessagesDelayed"
]
}));
const queueHealth = {
messagesAvailable: parseInt(metrics.Attributes?.ApproximateNumberOfMessages || "0"),
messagesInFlight: parseInt(metrics.Attributes?.ApproximateNumberOfMessagesNotVisible || "0"),
messagesDelayed: parseInt(metrics.Attributes?.ApproximateNumberOfMessagesDelayed || "0")
};
console.log("Queue health:", queueHealth);
// Alert if queue is backing up
if (queueHealth.messagesAvailable > 1000) {
console.warn("Queue backlog detected!");
}// Tag queues for cost allocation
await client.send(new TagQueueCommand({
QueueUrl: queueUrl,
Tags: {
"cost-center": "engineering",
"project": "user-notifications",
"environment": "production",
"auto-scaling": "enabled"
}
}));
// Bulk tag management for multiple queues
const queuesToTag = [
"https://sqs.us-east-1.amazonaws.com/123456789012/Queue1",
"https://sqs.us-east-1.amazonaws.com/123456789012/Queue2"
];
const commonTags = {
"managed-by": "terraform",
"backup": "enabled",
"monitoring": "cloudwatch"
};
for (const queueUrl of queuesToTag) {
await client.send(new TagQueueCommand({
QueueUrl: queueUrl,
Tags: commonTags
}));
}Install with Tessl CLI
npx tessl i tessl/npm-aws-sdk--client-sqs