Skip to main content

Firetail Lambda Package

Project description

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"
        })
    }

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

Firetail-Lambda-0.1.8.tar.gz (9.8 kB view hashes)

Uploaded Source

Built Distribution

Firetail_Lambda-0.1.8-py3-none-any.whl (6.2 kB view hashes)

Uploaded Python 3

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