emptygif
Language: English

All languages and frameworks

AWS Lambda (Python) Python

A Python snippet for AWS Lambda (Python) that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

AWS Lambda (Python) Python

File
lambda_function.py
# lambda_function.py - behind an API Gateway HTTP API route "GET /pixel.gif" or a function URL.
# Binary bodies travel base64-encoded, so the GIF stays in base64 here.
GIF_BASE64 = "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="


def lambda_handler(event, context):
    return {
        "statusCode": 200,
        "headers": {"Content-Type": "image/gif", "Cache-Control": "no-store"},
        "body": GIF_BASE64,
        "isBase64Encoded": True,
    }

We ran this snippet and compared the bytes it returned.

Check it

curl -sI http://localhost:8080/pixel.gif

Official site: AWS Lambda (Python)

More in Python