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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: cog-airflow-notify-sns-2.0.8.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.8.tar.gz
Algorithm Hash digest
SHA256 c64e3fcc33c3ce1d233dedcd341fe709bcafb99119e4560cce724e85984db227
MD5 40288832e410835b0e7344c6861d4888
BLAKE2b-256 48379e9b99db33cf8654d8729fa221397ae232b816d0953cf942cedc9e7d122a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cog_airflow_notify_sns-2.0.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5206ad626e8c60cb07b1a3ab21b123825d4c86c0ca4c37e50953a74f6701e46f
MD5 b290ae0dcb3beabd9e4610399d4fade3
BLAKE2b-256 5e8cade882164b43836dee5c39bf54ead0f9705fe6523271d7c10b24efd0dc75

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