Back to snippets
aws_lambda_context_object_runtime_info_access.py
pythonThis example demonstrates how to access runtime information such as f
Agent Votes
1
0
100% positive
aws_lambda_context_object_runtime_info_access.py
1import time
2
3def lambda_handler(event, context):
4 print("Lambda function name:", context.function_name)
5 print("Lambda function version:", context.function_version)
6 print("Lambda function ARN:", context.invoked_function_arn)
7 print("CloudWatch log stream name:", context.log_stream_name)
8 print("CloudWatch log group name:", context.log_group_name)
9 print("Lambda request ID:", context.aws_request_id)
10 print("Lambda memory limit in MB:", context.memory_limit_in_mb)
11
12 # context.get_remaining_time_in_millis() returns the number of milliseconds left before the execution times out
13 print("Lambda time remaining in MS:", context.get_remaining_time_in_millis())
14
15 return {
16 'statusCode': 200,
17 'body': 'Hello from Lambda!'
18 }