Skip to content

Commit

Permalink
Added SNS example DAG and rst (apache#21475)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferruzzi committed Feb 11, 2022
1 parent c922e2b commit b617496
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
39 changes: 39 additions & 0 deletions airflow/providers/amazon/aws/example_dags/example_sns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from datetime import datetime
from os import environ

from airflow import DAG
from airflow.providers.amazon.aws.operators.sns import SnsPublishOperator

SNS_TOPIC_ARN = environ.get('SNS_TOPIC_ARN', 'arn:aws:sns:us-west-2:123456789012:dummy-topic-name')

with DAG(
dag_id='example_sns',
schedule_interval=None,
start_date=datetime(2021, 1, 1),
tags=['example'],
catchup=False,
) as dag:

# [START howto_operator_sns_publish_operator]
publish = SnsPublishOperator(
task_id='publish_message',
target_arn=SNS_TOPIC_ARN,
message='This is a sample message sent to SNS via an Apache Airflow DAG task.',
)
# [END howto_operator_sns_publish_operator]
4 changes: 4 additions & 0 deletions airflow/providers/amazon/aws/operators/sns.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class SnsPublishOperator(BaseOperator):
"""
Publish a message to Amazon SNS.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:SnsPublishOperator`
:param aws_conn_id: aws connection to use
:param target_arn: either a TopicArn or an EndpointArn
:param message: the default message you want to send (templated)
Expand Down
2 changes: 2 additions & 0 deletions airflow/providers/amazon/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ integrations:
- integration-name: Amazon Simple Notification Service (SNS)
external-doc-url: https://aws.amazon.com/sns/
logo: /integration-logos/aws/[email protected]
how-to-guide:
- /docs/apache-airflow-providers-amazon/operators/sns.rst
tags: [aws]
- integration-name: Amazon Simple Queue Service (SQS)
external-doc-url: https://aws.amazon.com/sqs/
Expand Down
59 changes: 59 additions & 0 deletions docs/apache-airflow-providers-amazon/operators/sns.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.. Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
.. http://www.apache.org/licenses/LICENSE-2.0
.. Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Amazon Simple Notification Service (SNS) Operators
==================================================

`Amazon Simple Notification Service (Amazon SNS) <https://aws.amazon.com/sns/>`__ is a managed
service that provides message delivery from publishers to subscribers (also known as producers
and consumers). Publishers communicate asynchronously with subscribers by sending messages to
a topic, which is a logical access point and communication channel. Clients can subscribe to the
SNS topic and receive published messages using a supported endpoint type, such as Amazon Kinesis
Data Firehose, Amazon SQS, AWS Lambda, HTTP, email, mobile push notifications, and mobile text
messages (SMS).

Airflow provides an operator to publish messages to an SNS Topic.

Prerequisite Tasks
^^^^^^^^^^^^^^^^^^

.. include::/operators/_partials/prerequisite_tasks.rst
.. _howto/operator:SnsPublishOperator:

Publish A Message To An Existing SNS Topic
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To publish a message to an Amazon SNS Topic you can use
:class:`~airflow.providers.amazon.aws.operators.sns.SnsPublishOperator`.


.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_sns.py
:language: python
:dedent: 4
:start-after: [START howto_operator_sns_publish_operator]
:end-before: [END howto_operator_sns_publish_operator]


Reference
^^^^^^^^^

For further information, look at:

* `Boto3 Library Documentation for SNS <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sns.html>`__

0 comments on commit b617496

Please sign in to comment.