Naxi
Naxi

Reputation: 2046

How to capture request id inside a lambda function in a chalice app

I am having a chalice app which exposes some urls backed by api gateway and lambda function. What I want is to log the request id with each and every log msg for debugging purposes. Below is how my code looks like.

@app.route('/instrument', methods=['GET'])
@logging_and_error_handling()
def get_instrument_value():
 // some code
 // logger.log() Here I want to put the request id.

I can see that request id is getting logged in the cloudwatch by default. I want to use the same request id. How do I capture it inside my method ?

enter image description here

Upvotes: 1

Views: 3074

Answers (1)

saart
saart

Reputation: 402

You can use aws_request_id in the context object: https://docs.aws.amazon.com/lambda/latest/dg/python-context.html

Upvotes: 2

Related Questions