Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the unique identifier of the log stream for a AWS lambda function?

Context: We have a Lambda python function with many simultaneous invocations of the same function creating many unique log streams in cloudwatch. Additionally we use Xray on this lambda function. Using Xray we can quickly find an erroring invocation, however going from Xray to Cloudwatch is a pain, because the "Search Log Group" feature in the AWS console does not work as it will simply not load. Loading a specific log stream will work easily, hence we would like to annotate the Xray events with the name of the log stream.

Question: The unique identifier of the log stream uniquely identifies the container on which the lambda is running. I do not know however to get this id from inside to function such that I can pass it to xray. How to get the unique identifier of the log stream from inside a lambda function?

like image 831
Joost Avatar asked Jan 17 '26 08:01

Joost


1 Answers

Check out all the environment variables that are present in the AWS Lambda runtime environment. Specifically AWS_LAMBDA_LOG_GROUP_NAME and AWS_LAMBDA_LOG_STREAM_NAME.

like image 181
Mark B Avatar answered Jan 19 '26 22:01

Mark B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!