LinuxCommandLibrary

aws-sqs

Manage Amazon Simple Queue Service (SQS) queues

TLDR

List all availables queues

$ aws sqs list-queues
copy

Display the URL of a specific queue
$ aws sqs get-queue-url --queue-name [queue_name]
copy

Create a queue with specific attributes from a file in JSON format
$ aws sqs create-queue --queue-name [queue_name] --attributes [file://path/to/attributes_file.json]
copy

Send a specific message to a queue
$ aws sqs send-message --queue-url https://sqs.[region].amazonaws.com/[queue_name] --message-body "[message_body]" --delay-seconds [delay] --message-attributes [file://path/to/attributes_file.json]
copy

Delete the specified message from a queue
$ aws sqs delete-message --queue-url [https://queue_url] --receipt-handle [receipt_handle]
copy

Delete a specific queue
$ aws sqs delete-queue --queue-url https://sqs.[region].amazonaws.com/[queue_name]
copy

Delete all messages from the specified queue
$ aws sqs purge-queue --queue-url https://sqs.[region].amazonaws.com/[queue_name]
copy

Enable a specific AWS account to send messages to queue
$ aws sqs add-permission --queue-url https://sqs.[region].amazonaws.com/[queue_name] --label [permission_name] --aws-account-ids [account_id] --actions SendMessage
copy

SYNOPSIS

aws sqs [options and parameters]

PARAMETERS

create-queue
    Creates a new SQS queue.

--queue-name
    The name of the queue to create. This is required for create-queue.

--attributes
    A JSON structure containing attributes to set for the queue (e.g., VisibilityTimeout, MessageRetentionPeriod).

delete-queue
    Deletes an SQS queue.

--queue-url
    The URL of the queue to delete. This is required for delete-queue.

send-message
    Sends a message to an SQS queue.

--queue-url
    The URL of the queue to send the message to. This is required for send-message.

--message-body
    The body of the message to send. This is required for send-message.

--message-attributes
    A JSON structure containing message attributes to add to the message.

receive-message
    Receives messages from an SQS queue.

--queue-url
    The URL of the queue from which to receive messages. This is required for receive-message.

--max-number-of-messages
    The maximum number of messages to receive (up to 10).

--wait-time-seconds
    The duration (in seconds) for which the call waits for a message to arrive in the queue before returning. If a message is available, the call returns sooner than WaitTimeSeconds. If no messages are available and the wait time expires, the call returns a successful empty response. Requires a value between 0 and 20.

delete-message
    Deletes a message from an SQS queue.

--queue-url
    The URL of the queue from which to delete the message. This is required for delete-message.

--receipt-handle
    The receipt handle of the message to delete. This is required for delete-message.

get-queue-url
    Returns the URL of an existing Amazon SQS queue.

--queue-name
    The name of the queue whose URL must be fetched. This is required for get-queue-url.

--queue-owner-aws-account-id
    The account ID of the queue's owner if you want to get the queue's URL.

list-queues
    Returns a list of your queues in the current region.

--queue-name-prefix
    A string to use for filtering the list results. Only queues whose name begins with the specified string are returned.

--cli-input-json
    Provides input to the CLI command as JSON text.

--generate-cli-skeleton
    Prints a JSON skeleton to standard output, without sending an API request. If provided with no value or the value ``input``, prints a sample input JSON that can be used as an argument for ``--cli-input-json``. If provided with the value ``output``, it validates the command inputs and returns a sample output JSON for that command.

DESCRIPTION

The `aws sqs` command is part of the AWS Command Line Interface (CLI) and allows you to interact with Amazon Simple Queue Service (SQS). SQS is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. Using `aws sqs`, you can create, delete, send messages to, receive messages from, and manage the attributes of SQS queues. This tool provides a convenient way to manage your SQS queues directly from the command line, automating tasks and integrating with scripts. This eliminates the need to navigate the AWS Management Console for basic SQS operations, offering increased efficiency and programmatic control over your queue infrastructure. Its functionality spans from simple message sending to complex queue configuration, ensuring adaptability for various operational requirements. The AWS CLI needs to be configured before usage.

CAVEATS

Proper AWS credentials and configuration are required for this command to function correctly. Ensure you have the AWS CLI installed and configured with the necessary permissions to interact with SQS.

ERROR HANDLING

The `aws sqs` command provides error messages that can help diagnose problems. Common errors include authentication issues, incorrect queue URLs, and permission problems. Always check the AWS CLI configuration and queue permissions when encountering errors.

QUEUE ATTRIBUTES

When creating or updating queues, you can specify various attributes such as `VisibilityTimeout` (the duration a message is invisible after being received), `MessageRetentionPeriod` (how long messages are kept in the queue), and `MaximumMessageSize`. Carefully configuring these attributes is essential for optimal queue performance and reliability.

FIFO QUEUES

SQS supports FIFO (First-In-First-Out) queues, which guarantee that messages are processed in the order they were sent. When creating a FIFO queue, the queue name must end with `.fifo`, and you must also provide a `MessageGroupId` when sending messages. The `--message-deduplication-id` is also important for deduplication.

SECURITY CONSIDERATIONS

When using `aws sqs`, it is crucial to follow security best practices.
Always use the principle of least privilege when granting permissions to SQS queues. Specifically, grant users and applications only the necessary permissions, such as `sqs:SendMessage`, `sqs:ReceiveMessage`, and `sqs:DeleteMessage`, instead of broader permissions like `sqs:*`. This helps limit the potential impact of security vulnerabilities.

When transmitting sensitive data, consider encrypting message bodies at rest and in transit. SQS supports server-side encryption (SSE) using AWS Key Management Service (KMS). If client side encryption is needed, it can be implemented in the software application that will use the queue.

HISTORY

The `aws sqs` command has evolved as part of the broader AWS CLI, mirroring the development and feature additions to Amazon SQS itself. As SQS added capabilities such as message attributes, FIFO queues, and dead-letter queues, the `aws sqs` command was updated to provide command-line access to these features.

Early versions focused on basic queue management (create, delete, send, receive). Subsequent updates included finer-grained control over queue attributes, message handling, and improved error reporting. The command's popularity grew with the increasing adoption of microservices and serverless architectures, where SQS plays a crucial role in decoupling components.

SEE ALSO

aws(1), aws configure(1)

Copied to clipboard