Amazon SQS

Amazon Simple Queue Service (SQS) is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity and overhead associated with managing and operating message-oriented middleware, and empowers developers to focus on differentiating work. Using SQS, you can send, store, and receive messages between software components at any volume, without losing messages or requiring other services to be available.

Prerequisite Tasks

To use these operators, you must do a few things:

Operators

Publish a message to an Amazon SQS queue

To publish a message to an Amazon SQS queue you can use the SqsPublishOperator

In the following example, the task publish_to_queue publishes a message containing the task instance and the execution date to a queue with a default name of Airflow-Example-Queue.

airflow/providers/amazon/aws/example_dags/example_sqs.py[source]

publish_to_queue = SqsPublishOperator(
    task_id='publish_to_queue',
    sqs_queue=create_queue,
    message_content="{{ task_instance }}-{{ execution_date }}",
)

Sensors

Read messages from an Amazon SQS queue

To read messages from an Amazon SQS queue until exhausted use the SqsSensor

airflow/providers/amazon/aws/example_dags/example_sqs.py[source]

read_from_queue = SqsSensor(
    task_id='read_from_queue',
    sqs_queue=create_queue,
)

Was this entry helpful?