Amazon SQS Operators¶
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:
Create necessary resources using AWS Console or AWS CLI.
Install API libraries via pip.
pip install 'apache-airflow[amazon]'
Detailed information is available Installation
Amazon SQS Publish Operator¶
To publish a message to an Amazon SQS queue 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
.
publish_to_queue = SqsPublishOperator(
task_id='publish_to_queue',
sqs_queue=create_queue,
message_content="{{ task_instance }}-{{ execution_date }}",
)
Amazon SQS Sensor¶
To read messages from an Amazon SQS queue until exhausted use the
SqsPublishOperator
read_from_queue = SqsSensor(
task_id='read_from_queue',
sqs_queue=create_queue,
)