
Node.js version 16.0 or higher is required.
Which language is your AWS Lambda using?
Collect logs from your AWS Lambda running Node.js code.
Build and upload stockstory/logtail-lambda-extension Lambda layer to your AWS:
git clone git@github.com:stockstory/logtail-lambda-extension.git
cd logtail-lambda-extension
pnpm install
pnpm run build
aws lambda publish-layer-version \
--layer-name "logtail-lambda-extension" \
--zip-file "fileb://./dist/extension.zip" \
--compatible-runtimes nodejs16.x nodejs18.x \
--compatible-architectures x86_64 arm64
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.
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.
In your AWS Console, set up LOGTAIL_TOKEN
environment variable for the AWS Lambda functions with your source token as value. You can get your source tokens in your sources in Better Stack Logs.
This can be done in Lambda -> Functions -> your function -> Configuration -> Environment variables. For details, check AWS docs.
Use the logger as usual:
console.error('Something bad happened.')
console.info('Log message with structured logging.', {
'item': "Orange Soda",
'price': 100.00
})
You should see your logs in Better Stack -> Live tail.
Node.js version 16.0 or higher is required.
Collect logs from your AWS Lambda running Python code.
Install Logtail Python and AWS Lambda Powertools PyPI packages:
pip3 install logtail-python
pip3 install aws-lambda-powertools
Set up AWS Lambda logger with Better Stack:
from logtail import LogtailHandler
from aws_lambda_powertools import Logger
handler = LogtailHandler(source_token="$SOURCE_TOKEN")
logger = Logger(service="example-service", logger_handler=handler, level="INFO")
Use the logger as usual:
logger.error('Something bad happened.')
logger.info('Log message with structured logging.', extra={
'item': "Orange Soda",
'price': 100.00
})
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.
Please let us know at hello@betterstack.com.
We're happy to help! ๐
Interested in learning more about enriching log context and using formatters?
Head over to official AWS Lambda Powertools documentation.