Skip to main content

Firetail Python Lambda Middleware

PyPI package version number Actions Status License: LGPL v3 codecov

Overview

The purpose of this module is to correctly log out the AWS Lambda event and response payload to allow the firetail extension to then send it on to the firetail logging api

The firetail_handler is a decorator that wraps around an event handler function in a AWS Lambda to extract the event and response payloads into a base64 logging message.

###Supported Lambda Runtimes ✅ Python 3.7 ✅ Python 3.8 ✅ Python 3.9

Installation

Install the module with using pip

pip install -U firetail-lambda

Implementing Middleware in lambda function

import json
from firetail_lambda import firetail_handler, firetail_app

app = firetail_app()

@firetail_handler(app)
def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "Hello"
        })
    }

Multiple Event handlers

import json
from firetail_lambda import firetail_handler, firetail_app

app = firetail_app()

@firetail_handler(app)
def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "Hello"
        })
    }

@firetail_handler(app)
def lambda_handler_2(event, context):
    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "Hello 2"
        })
    }

Custom Sanitization callback

import copy
import json
from firetail_lambda import firetail_handler, firetail_app

def sanitize_payloads(event, response):
    new_event = copy.copy(event)
    remove_headers = ['authorization','Authorization', 'x-api-key']
    if 'headers' in event:
        for header in remove_headers:
            if header in event['headers']:
                del new_event['headers'][header]
            if 'multiValueHeaders' in event and header in event['multiValueHeaders']:
                del new_event['multiValueHeaders'][header]
                        
    return new_event, response

app = firetail_app()
app.sanitization_callback = sanitize_payloads

@firetail_handler(app)
def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "body": json.dumps({
            "message": "Hello"
        })
    }

Metadata

Release files for Firetail-Lambda 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Firetail-Lambda 0.1.8
File Size Uploaded
Firetail-Lambda-0.1.8.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Firetail-Lambda 0.1.8
File Interpreter ABI Platform
Firetail_Lambda-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / Firetail-Lambda-0.1.8.tar.gz

Download URL Firetail-Lambda-0.1.8.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
21500771f92f2f4969211982c577339eb9e6666c691c5fc8e64df0ea7b408bf8
BLAKE2b-256 checksum
How to use checksums
cb555feaf8c7d295aeddcd8c0ab8e2ef479ebfde190c13154bb357f01602caea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release files / Firetail_Lambda-0.1.8-py3-none-any.whl

Download URL Firetail_Lambda-0.1.8-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1a7957e16bb29115a000bc2866840f443393849bef614688e3c27c8c53bedde
BLAKE2b-256 checksum
How to use checksums
90714be4b967d17c9c6803ffc67ef4a0c05d1378328213539bd6dccdd3e1a54e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page