Using highlight.io with Python on AWS Lambda
Make sure that you followed the fullstack mapping guide.
H.init("<YOUR_PROJECT_ID>", {
tracingOrigins: ['localhost', 'example.myapp.com/backend'],
networkRecording: {
enabled: true,
recordHeadersAndBody: true,
},
});
Download the package from pypi and save it to your requirements. If you use a zip or s3 file upload to publish your function, you will want to make sure highlight-io
is part of the build.
poetry add highlight-io
# or with pip
pip install highlight-io
Setup the SDK. Add the @observe_handler
decorator to your lambdas.
import highlight_io
from highlight_io.integrations.aws import observe_handler
H = highlight_io.H("1", record_logs=True)
@observe_handler
def lambda_handler(event, context):
return {
"statusCode": 200,
"body": f"Hello, {name}. This HTTP triggered function executed successfully.",
}
Check that your installation is valid by throwing an error. Add an operation that raises an exception to your lambda handler. Setup an HTTP trigger and visit your lambda on the internet. You should see a DivideByZero
error in the Highlight errors page within a few moments.
import highlight_io
from highlight_io.integrations.aws import observe_handler
H = highlight_io.H("1", record_logs=True)
@observe_handler
def lambda_handler(event, context):
return {
"body": f"Returning this is a bad idea: {5 / 0}.",
}
With the Python SDK, your logs are reported automatically from the builtin logging methods (as long as record_logs=True
is provided to the highlight_io.H
constructor). Visit the highlight logs portal and check that backend logs are coming in.