Better Stack AWS Lambda logging | Better Stack Documentation

Which language is your AWS Lambda using?

Logging in AWS Lambda running Node.js

Collect logs from your AWS Lambda running Node.js code.

1. Install

Build and upload stockstory/logtail-lambda-extension Lambda layer to your AWS:

Build and upload Lambda layer

Copied!

Take care to publish the layer in the region your Lambda function reside in. If that's not your default region, you can change it by adding --region <region-name> parameter to the command above.

Using a Window machine?

To avoid compatibility issues caused by different line endings, build and upload the Lambda layer using WSL.

2. Add layer to your Lambda functions

In your AWS Console, add the logtail-lambda-extension layer to the Node.js Lambda functions you want to collect logs from.

This can be done in Lambda → Functions → your function → Layers section.
For details, check AWS docs.

3. Configure your source token

In your AWS Console, set up LOGTAIL_TOKEN and LOGTAIL_HTTP_API_URL environment variables for the AWS Lambda functions like this:

Environment variables

Copied!

LOGTAIL_TOKEN:        $SOURCE_TOKEN
LOGTAIL_HTTP_API_URL: https://$INGESTING_HOST/

This can be done in Lambda → Functions → your function → Configuration → Environment variables. For details, check AWS docs.

4. Start logging 🎉

Use the logger as usual:

Send logs to Better Stack

Copied!

You should see your logs in Better Stack → Logs & traces.

Node.js version 16.0 or higher is required.

Logging in AWS Lambda running Python

Collect logs from your AWS Lambda running Python code.

1. Install

Install Logtail Python and AWS Lambda Powertools PyPI packages:

Install PyPI packages

Copied!

2. Setup

Set up AWS Lambda logger with Better Stack:

Set up Logtail handler

Copied!

3. Start logging 🎉

Use the logger as usual:

Send logs to Better Stack

Copied!

You should see your logs in Better Stack → Live tail.

Python version 3.7 or higher is required.
Pip version 20.0.2 or higher is required.

Need help?

Please let us know at hello@betterstack.com.
We're happy to help! 🙏

Additional information

Interested in learning more about enriching log context and using formatters?
Head over to official AWS Lambda Powertools documentation.