airflow.providers.amazon.aws.triggers.sqs

Module Contents

Classes

SqsSensorTrigger

Asynchronously get messages from an Amazon SQS queue and then delete the messages from the queue.

class airflow.providers.amazon.aws.triggers.sqs.SqsSensorTrigger(sqs_queue, aws_conn_id='aws_default', max_messages=5, num_batches=1, wait_time_seconds=1, visibility_timeout=None, message_filtering=None, message_filtering_match_values=None, message_filtering_config=None, delete_message_on_reception=True, waiter_delay=60, region_name=None, verify=None, botocore_config=None)[source]

Bases: airflow.triggers.base.BaseTrigger

Asynchronously get messages from an Amazon SQS queue and then delete the messages from the queue.

Parameters
  • sqs_queue (str) – The SQS queue url

  • aws_conn_id (str | None) – AWS connection id

  • max_messages (int) – The maximum number of messages to retrieve for each poke (templated)

  • num_batches (int) – The number of times the sensor will call the SQS API to receive messages (default: 1)

  • wait_time_seconds (int) – The time in seconds to wait for receiving messages (default: 1 second)

  • visibility_timeout (int | None) – Visibility timeout, a period of time during which Amazon SQS prevents other consumers from receiving and processing the message.

  • message_filtering (airflow.providers.amazon.aws.utils.sqs.MessageFilteringType | None) – Specified how received messages should be filtered. Supported options are: None (no filtering, default), ‘literal’ (message Body literal match) or ‘jsonpath’ (message Body filtered using a JSONPath expression). You may add further methods by overriding the relevant class methods.

  • message_filtering_match_values (Any) – Optional value/s for the message filter to match on. For example, with literal matching, if a message body matches any of the specified values then it is included. For JSONPath matching, the result of the JSONPath expression is used and may match any of the specified values.

  • message_filtering_config (Any) – Additional configuration to pass to the message filter. For example with JSONPath filtering you can pass a JSONPath expression string here, such as ‘foo[*].baz’. Messages with a Body which does not match are ignored.

  • delete_message_on_reception (bool) – Default to True, the messages are deleted from the queue as soon as being consumed. Otherwise, the messages remain in the queue after consumption and should be deleted manually.

  • waiter_delay (int) – The time in seconds to wait between calls to the SQS API to receive messages.

property hook: airflow.providers.amazon.aws.hooks.sqs.SqsHook[source]
serialize()[source]

Return the information needed to reconstruct this Trigger.

Returns

Tuple of (class path, keyword arguments needed to re-instantiate).

Return type

tuple[str, dict[str, Any]]

async poll_sqs(client)[source]

Asynchronously poll SQS queue to retrieve messages.

Parameters

client (airflow.providers.amazon.aws.hooks.base_aws.BaseAwsConnection) – SQS connection

Returns

A list of messages retrieved from SQS

Return type

collections.abc.Collection

async poke(client)[source]
async run()[source]

Run the trigger in an asynchronous context.

The trigger should yield an Event whenever it wants to fire off an event, and return None if it is finished. Single-event triggers should thus yield and then immediately return.

If it yields, it is likely that it will be resumed very quickly, but it may not be (e.g. if the workload is being moved to another triggerer process, or a multi-event trigger was being used for a single-event task defer).

In either case, Trigger classes should assume they will be persisted, and then rely on cleanup() being called when they are no longer needed.

Was this entry helpful?