Skip to main content

Publish Airflow notification errors to SNS Topic

Project description

Python 3.7 PyPI version License: MIT Twitter Follow

Publish Airflow Notification to a SNS Topic

This package adds a callback function to use in failures to DAGs and Tasks in a Airflow project.

Installation

pip install cog-airflow-notify-sns==1.0.0

Usage

from datetime import timedelta

# Airflow native imports to create a DAG
from airflow import DAG, utils
from airflow.operators.bash_operator import BashOperator

# Here is function import
from airflow_notify_sns import airflow_notify_sns

# Dag Definition
dag = DAG(
    dag_id='test_dag',
    default_args={
        'owner': 'Cognitivo.ai',
        'depends_on_past': False,
        'start_date': utils.dates.days_ago(1),
        'retries': 3,
        'retry_delay': timedelta(minutes=5)
    },
    schedule_interval="@daily",
    dagrun_timeout=timedelta(minutes=60),
    sla_miss_callback=airflow_notify_sns #here
)

# Add your tasks here
t = BashOperator(
    dag=dag,
    task_id='test_env',
    bash_command='/tmp/test.sh',
    env={'EXECUTION_DATE': '{{ ds }}'},
    on_failure_callback=airflow_notify_sns #here
)

When DAG or tasks ends in error, a notification will be send to a SNS Topic using AWS default connection (aws_default).

Required Variable

This module will try to find a variable named airflow_alerts_config in your Airflow environment.

Example

{
    "sns_topic_arn": "arn:aws:sns:us-east-1:012345678901:topic-name",
    "airflow_url": "xpto.us-east-1.elb.amazonaws.com:8080"
}

If variable is not found, function will abort execution with no error.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cog-airflow-notify-sns-2.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

cog_airflow_notify_sns-2.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file cog-airflow-notify-sns-2.0.1.tar.gz.

File metadata

File hashes

Hashes for cog-airflow-notify-sns-2.0.1.tar.gz
Algorithm Hash digest
SHA256 52c001ce5172fed80ba4db637e6cd4f9ab58c16994681c1d1d39aca79ec4969f
MD5 264d58be98b02797008a95fc54be98bf
BLAKE2b-256 9938f8639033514d023040657854f17a80ef614444860cd71f74f9312b4d5b89

See more details on using hashes here.

File details

Details for the file cog_airflow_notify_sns-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cog_airflow_notify_sns-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f9afdc900fac8f4148d61b4b1ff786b892e140a19e2972b07d4a690ef917d3c
MD5 a85d43167869f83578b68b7948394b89
BLAKE2b-256 12e5a252065c3e675fb18d85498a0591c3ecca16de02f06ca61ab7c06389dc3d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page