This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of sending MS Teams Notifications on DAG failure (Airflow 2.0.0+) | |
import requests | |
from airflow.decorators import dag, task | |
from airflow.operators.python import task, get_current_context | |
from airflow.utils.dates import days_ago | |
from airflow.models import DagRun | |
# from airflow.models import Variable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import asyncio | |
from airflow.decorators import dag, task | |
from airflow.operators.python import task | |
from datetime import date, datetime, timedelta | |
async def async_main(): | |
async with aiohttp.ClientSession() as session: | |
async with session.get('http://httpbin.org/get') as resp: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import nest_asyncio | |
nest_asyncio.apply() | |
from random import randint | |
class HttpClient: | |
def __init__(self, session, concurrency): | |
self.__session = session | |
self.concurrency = asyncio.Semaphore(concurrency) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
x-airflow-common: | |
&airflow-common | |
image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.0.1-python3.8} | |
environment: | |
&airflow-common-env | |
AIRFLOW__CORE__EXECUTOR: CeleryExecutor | |
AIRFLOW__CORE__SQL_ALCHEMY_CONN: postgresql+psycopg2://airflow:airflow@postgres/airflow | |
AIRFLOW__CELERY__RESULT_BACKEND: db+postgresql://airflow:airflow@postgres/airflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
postgres: | |
image: postgres:13.2 | |
ports: | |
- 5432:5432 | |
environment: | |
POSTGRES_USER: example | |
POSTGRES_PASSWORD: example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
import hmac | |
import hashlib | |
import uuid | |
def get_authorization_header(key: str) -> str: | |
nonce = 'YOUR_NONCE_PREFIX' + str(uuid.uuid4()) | |
authorization = "key=" + key + ",timestamp=" + str(int(time())) + ",nonce=" + nonce | |
return authorization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Credits to Meleu @ https://meleu.sh/urlencode/ | |
# Usage: urlencode "#" => will output "%23" | |
urlencode() { | |
local LC_ALL=C | |
local string="$*" | |
local length="${#string}" | |
local char |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import time | |
# Enter the region your instances are in, e.g. 'us-east-1' | |
region = 'us-east-1' | |
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX'] | |
instances = ['i-0ab7xdx71x8xeff33'] | |
def lambda_handler(event, context): | |
ec2 = boto3.client('ec2', region_name=region) | |
ec2.start_instances(InstanceIds=instances) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import time | |
# Enter the region your instances are in, e.g. 'us-east-1' | |
region = 'us-east-1' | |
# Enter your instances here: ex. ['X-XXXXXXXX', 'X-XXXXXXXX'] | |
instances = ['i-03c24cxbd9x10ex51'] | |
def lambda_handler(event, context): | |
ec2 = boto3.client('ec2', region_name=region) | |
ec2.stop_instances(InstanceIds=instances) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
aws cloudwatch tag-resource --resource-arn arn:aws:cloudwatch:us-east-1:012345678901:alarm:Alarm-Name --tags Key=Example,Value=OK Key=Another,Value=Okay |