Docs▸Python SDK

AWS Lambda

Monitor your Python Lambda function and send its data at the end of each invocation.

Set up your function

Package the SDK and telemetry.py with your Lambda function, and set the VIGILON_* environment variables from the Python quickstart. Vigilon detects the Lambda runtime on its own and sends each invocation’s data before Lambda freezes the function, so nothing is lost between invocations.

For this example, set the Lambda handler to lambda_function.handler. Startup runs once, when Lambda loads the module, not on every invocation:

lambda_function.py
def handler(event, context):
    import boto3

    s3 = boto3.client("s3")
    response = s3.list_buckets()
    return {"bucket_count": len(response.get("Buckets", []))}


from telemetry import start_vigilon

start_vigilon()
Note

This is the reverse of the quickstart’s order, and it is deliberate. On Lambda, define the handler first and start Vigilon after it, so Vigilon can wrap the handler. Still create clients such as boto3 after startup, for example inside the handler.

The example needs the usual AWS permission to list S3 buckets. Replace that call with your function’s work. You do not need to send data yourself at the end of each invocation, or call register() inside the handler. Locally, where AWS_LAMBDA_FUNCTION_NAME is not set, Lambda monitoring stays off.