ExAws. SQS
(ExAws.SQS v5.1.0)
View Source
Operations on AWS SQS.
This is a modernized fork of the archived
ex-aws/ex_aws_sqs. The biggest change is that every
operation now speaks the SQS JSON protocol (AmazonSQS.<Action> over
application/x-amz-json-1.0) instead of the legacy Query/XML protocol. See the README for
the full list of changes and a migration guide.
Responses
Because requests are built with ExAws.Operation.JSON, a successful ExAws.request/1 call
returns {:ok, response} where response is the JSON response body decoded as-is by your
configured :json_codec (Elixir's built-in JSON module since 1.18, Jason, etc.): a map with
the exact field names AWS documents, e.g. %{"MessageId" => "...", "MD5OfMessageBody" => "..."}
for send_message/3. There is no extra normalization layer; whatever the
AWS API Reference
says a call returns is what you get back, keyed exactly as documented (a handful of AWS
operations use unusual casing, e.g. list_dead_letter_source_queues/1 returns "queueUrls"
with a lowercase q — that's an AWS quirk, not a bug here).
Summary
Queues
Create queue.
Delete a queue
Gets attributes of a SQS Queue
Get queue URL
Retrieves the dead letter source queues for a given SQS Queue
Retrieves a list of all the SQS Queues
Purge all messages in a SQS Queue
Set attributes of a SQS Queue.
Streaming
Returns a lazy stream of dead-letter source queue URLs for queue_url, transparently
fetching additional pages with list_dead_letter_source_queues/2 (NextToken) as the
stream is consumed.
Returns a lazy stream of queue URLs, transparently fetching additional pages with
list_queues/1 (NextToken) as the stream is consumed.
Queues
@spec create_queue( queue_name :: binary(), queue_attributes :: queue_attributes(), tags :: map() ) :: ExAws.Operation.JSON.t()
Create queue.
Attributes
:delay_seconds- The length of time, in seconds, for which the delivery of all messages in the queue is delayed. Valid values: An integer from 0 to 900 seconds (15 minutes). Default: 0.:maximum_message_size- The limit of how many bytes a message can contain before Amazon SQS rejects it. Valid values: An integer from 1,024 bytes (1 KiB) to 1,048,576 bytes (1 MiB). Default: 1,048,576 bytes (1 MiB).:message_retention_period- The length of time, in seconds, for which Amazon SQS retains a message. Valid values: An integer from 60 seconds (1 minute) to 1,209,600 seconds (14 days). Default: 345,600 (4 days).:policy- The queue's policy. A valid AWS policy. For more information about policy structure, see Overview of AWS IAM Policies in the Amazon IAM User Guide.:receive_message_wait_time_seconds- The length of time, in seconds, for which a ReceiveMessage action waits for a message to arrive. Valid values: An integer from 0 to 20 (seconds). Default: 0.:redrive_policy- The string that includes the parameters for the dead-letter queue functionality of the source queue as a JSON object. For more information about the redrive policy and dead-letter queues, see Using Amazon SQS Dead-Letter Queues in the Amazon Simple Queue Service Developer Guide.deadLetterTargetArn– The Amazon Resource Name (ARN) of the dead-letter queue to which Amazon SQS moves messages after the value of maxReceiveCount is exceeded.maxReceiveCount– The number of times a message is delivered to the source queue before being moved to the dead-letter queue. When the ReceiveCount for a message exceeds the maxReceiveCount for a queue, Amazon SQS moves the message to the dead-letter-queue.
Note
The dead-letter queue of a FIFO queue must also be a FIFO queue. Similarly, the dead-letter queue of a standard queue must also be a standard queue.
:visibility_timeout- The visibility timeout for the queue, in seconds. Valid values: An integer from 0 to 43,200 (12 hours). Default: 30. For more information about the visibility timeout, see Visibility Timeout in the Amazon Simple Queue Service Developer Guide.:fifo_queue- Designates a queue as FIFO. Valid values: true, false. If you don't specify the FifoQueue attribute, Amazon SQS creates a standard queue. You can provide this attribute only during queue creation. You can't change it for an existing queue. When you set this attribute, you must also provide the MessageGroupId for your messages explicitly. For more information, see FIFO Queue Logic in the Amazon Simple Queue Service Developer Guide.:content_based_deduplication- Enables content-based deduplication. Valid values: true, false. For more information, see Exactly-Once Processing in the Amazon Simple Queue Service Developer Guide.:kms_master_key_id- The ID of an AWS-managed customer master key (CMK) for Amazon SQS or a custom CMK. For more information, see Key Terms. While the alias of the AWS-managed CMK for Amazon SQS is always alias/aws/sqs, the alias of a custom CMK can, for example, be alias/MyAlias . For more examples, see KeyId in the AWS Key Management Service API Reference.:kms_data_key_reuse_period_seconds- The length of time, in seconds, for which Amazon SQS can reuse a data key to encrypt or decrypt messages before calling AWS KMS again. An integer representing seconds, between 60 seconds (1 minute) and 86,400 seconds (24 hours). Default: 300 (5 minutes).:sqs_managed_sse_enabled- Enables server-side queue encryption using SQS owned encryption keys. Valid values: true, false.
Examples
iex> ExAws.SQS.create_queue("my-queue", [visibility_timeout: 60], %{"team" => "platform"}).data
%{
"Attributes" => %{"VisibilityTimeout" => "60"},
"QueueName" => "my-queue",
"tags" => %{"team" => "platform"}
}
@spec delete_queue(queue_url :: binary()) :: ExAws.Operation.JSON.t()
Delete a queue
@spec get_queue_attributes( queue_url :: binary(), attribute_names :: :all | [sqs_queue_attribute_name(), ...] ) :: ExAws.Operation.JSON.t()
Gets attributes of a SQS Queue
@spec get_queue_url( queue_name :: binary(), opts :: [{:queue_owner_aws_account_id, binary()}] ) :: ExAws.Operation.JSON.t()
Get queue URL
Options
:queue_owner_aws_account_id- The AWS account ID of the account that created the queue.
@spec list_dead_letter_source_queues( queue_url :: binary(), opts :: [max_results: pos_integer(), next_token: binary()] ) :: ExAws.Operation.JSON.t()
Retrieves the dead letter source queues for a given SQS Queue
Options
:max_results- Maximum number of results to include in the response (1..1000). Set this option to receive aNextTokenwhen more results exist.:next_token- Pagination token from a previous call, used to retrieve the next page of results.
@spec list_queues( opts :: [ queue_name_prefix: binary(), max_results: pos_integer(), next_token: binary() ] ) :: ExAws.Operation.JSON.t()
Retrieves a list of all the SQS Queues
Options
:queue_name_prefix- A string to use for filtering the list results. Only those queues whose name begins with the specified string are returned. Queue URLs and names are case-sensitive.:max_results- Maximum number of results to include in the response (1..1000). Set this option to receive aNextTokenwhen more results exist.:next_token- Pagination token from a previous call, used to retrieve the next page of results.
@spec purge_queue(queue_url :: binary()) :: ExAws.Operation.JSON.t()
Purge all messages in a SQS Queue
@spec set_queue_attributes(queue_url :: binary(), attributes :: queue_attributes()) :: ExAws.Operation.JSON.t()
Set attributes of a SQS Queue.
Messages
Message move tasks (DLQ redrive)
Streaming
@spec stream_dead_letter_source_queues( queue_url :: binary(), opts :: [max_results: pos_integer(), next_token: binary()], request_opts :: keyword() ) :: Enumerable.t(binary())
Returns a lazy stream of dead-letter source queue URLs for queue_url, transparently
fetching additional pages with list_dead_letter_source_queues/2 (NextToken) as the
stream is consumed.
Like stream_queues/2: takes :max_results (default 1000) and :next_token, plus optional
ExAws.request/2 config overrides, and raises ExAws.SQS.PaginationError if a page request fails.
(list_message_move_tasks/2 has no stream counterpart — the AWS operation returns a
bounded list of recent tasks and supports no NextToken pagination.)
@spec stream_queues( opts :: [ queue_name_prefix: binary(), max_results: pos_integer(), next_token: binary() ], request_opts :: keyword() ) :: Enumerable.t(binary())
Returns a lazy stream of queue URLs, transparently fetching additional pages with
list_queues/1 (NextToken) as the stream is consumed.
Takes the same options as list_queues/1 (:queue_name_prefix, :max_results, :next_token),
plus an optional list of ExAws.request/2 config overrides (e.g. a different :region, or
an alternative :http_client).
Defaults :max_results to 1000 so AWS returns continuation tokens when more queues exist.
Set :next_token to resume from a previous page.
Each page is fetched with ExAws.request/2; the stream raises ExAws.SQS.PaginationError
(carrying the original error in :reason) if a page request fails.
ExAws.SQS.stream_queues(queue_name_prefix: "prod-") |> Enum.to_list()
# => ["https://sqs.us-east-1.amazonaws.com/123/prod-a", ...]
Types
@type message_visibility_batch_item() :: %{ id: binary(), receipt_handle: binary(), visibility_timeout: visibility_timeout() }
@type queue_attributes() :: [ policy: binary(), visibility_timeout: visibility_timeout(), maximum_message_size: 1024..1_048_576, message_retention_period: 60..1_209_600, approximate_number_of_messages: binary(), approximate_number_of_messages_not_visible: binary(), created_timestamp: binary(), last_modified_timestamp: binary(), queue_arn: binary(), approximate_number_of_messages_delayed: binary(), delay_seconds: 0..900, receive_message_wait_time_seconds: 0..20, redrive_policy: binary(), redrive_allow_policy: binary(), fifo_queue: boolean(), content_based_deduplication: boolean(), kms_master_key_id: binary(), kms_data_key_reuse_period_seconds: 60..86400, deduplication_scope: binary(), fifo_throughput_limit: binary(), sqs_managed_sse_enabled: boolean() ]
@type receive_message_opts() :: [ attribute_names: :all | [sqs_message_attribute_name(), ...], message_attribute_names: :all | [String.Chars.t(), ...], max_number_of_messages: 1..10, visibility_timeout: visibility_timeout(), wait_time_seconds: 0..20, receive_request_attempt_id: String.t() ]
@type sqs_acl() :: %{required(binary()) => :all | [sqs_permission(), ...]}
@type sqs_batch_message() :: map() | [ id: binary(), message_body: binary(), delay_seconds: 0..900, message_attributes: sqs_message_attribute() | [sqs_message_attribute(), ...], message_system_attributes: sqs_message_system_attribute() | [sqs_message_system_attribute(), ...], message_deduplication_id: binary(), message_group_id: binary() ]
@type sqs_message_attribute_name() ::
:sender_id
| :sent_timestamp
| :approximate_receive_count
| :approximate_first_receive_timestamp
| :sequence_number
| :message_deduplication_id
| :message_group_id
| :aws_trace_header
| :dead_letter_queue_source_arn
@type sqs_message_opts() :: [ delay_seconds: 0..900, message_attributes: sqs_message_attribute() | [sqs_message_attribute(), ...], message_system_attributes: sqs_message_system_attribute() | [sqs_message_system_attribute(), ...], message_deduplication_id: binary(), message_group_id: binary() ]
@type sqs_permission() ::
:send_message
| :receive_message
| :delete_message
| :change_message_visibility
| :get_queue_attributes
@type sqs_queue_attribute_name() ::
:policy
| :visibility_timeout
| :maximum_message_size
| :message_retention_period
| :approximate_number_of_messages
| :approximate_number_of_messages_not_visible
| :created_timestamp
| :last_modified_timestamp
| :queue_arn
| :approximate_number_of_messages_delayed
| :delay_seconds
| :receive_message_wait_time_seconds
| :redrive_policy
| :redrive_allow_policy
| :fifo_queue
| :content_based_deduplication
| :kms_master_key_id
| :kms_data_key_reuse_period_seconds
| :deduplication_scope
| :fifo_throughput_limit
| :sqs_managed_sse_enabled
@type visibility_timeout() :: 0..43200