SqsSensor

Amazon

Get messages from an Amazon SQS queue and then delete the messages from the queue. If deletion of messages fails, an AirflowException is thrown. Otherwise, the messages are pushed through XCom with the key messages.

View on GitHub

Last Updated: Jan. 19, 2023

Access Instructions

Install the Amazon provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

aws_conn_idAWS connection id
sqs_queueRequiredThe SQS queue url (templated)
max_messagesThe maximum number of messages to retrieve for each poke (templated)
num_batchesThe number of times the sensor will call the SQS API to receive messages (default: 1)
wait_time_secondsThe time in seconds to wait for receiving messages (default: 1 second)
visibility_timeoutVisibility timeout, a period of time during which Amazon SQS prevents other consumers from receiving and processing the message.
message_filteringSpecified 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_valuesOptional 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_configAdditional 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_receptionDefault 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.

Documentation

Get messages from an Amazon SQS queue and then delete the messages from the queue. If deletion of messages fails, an AirflowException is thrown. Otherwise, the messages are pushed through XCom with the key messages.

By default,the sensor performs one and only one SQS call per poke, which limits the result to a maximum of 10 messages. However, the total number of SQS API calls per poke can be controlled by num_batches param.

See also

For more information on how to use this sensor, take a look at the guide: Read messages from an Amazon SQS queue

Was this page helpful?