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

Uploaded Source

Built Distribution

cog_airflow_notify_sns-2.0.5-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cog-airflow-notify-sns-2.0.5.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for cog-airflow-notify-sns-2.0.5.tar.gz
Algorithm Hash digest
SHA256 a99b98f01ecc685c38e7dde79dfcfd752d5ac999f363e710656336d13885ed25
MD5 7e851bbdc9efc6b3fff6c2944a5fae3e
BLAKE2b-256 c65934e16eb6ccda9ed2b96230bd55491c4e74b1f2dc5a07bc689e87127a3716

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cog_airflow_notify_sns-2.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for cog_airflow_notify_sns-2.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dc23d2d974e0d075f6d420f744ebf3bc44b0f8463d9678c24f4387459a87c0ec
MD5 96da99f19e40ad60486ef6764c5c1d4e
BLAKE2b-256 b358528473e2a69f005e7de671a6fe091720a3c4e07c851beef9cc908e53582f

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