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.2.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for cog-airflow-notify-sns-2.0.2.tar.gz
Algorithm Hash digest
SHA256 ea7f1971010689210d04dbaee91bd711cdab4804c9ca061a7eeabe3c4f83dd68
MD5 ba754c634e100ec25f258e6b14705d46
BLAKE2b-256 f37282741353144f605ba6ca0ae4ef1c15cd4ebc6041c079c85e1d44d6d94338

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cog_airflow_notify_sns-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a3954520e82a6fa5bbf7d18ede6827e60704bfef90c0451847809f9423a8cb5d
MD5 7a8ca4adfcf2d8145841eff12b45a070
BLAKE2b-256 dbfa90aa677ab6515a24d36aec23ab9fa5441e861f5248ef1e4267179a570f86

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