How to see context variable in lambda function

Viewed 2235

I set sample lambda function as follows to detect what is context. This function is hooked by API gateway.

import json

def lambda_handler(event, context):
    return {
        'isBase64Encoded': False,
        'statusCode': 200,
        'headers': {},
        'body': json.dumps(context)
    }

And when I send GET request from API gateway it returned as follows

{
  "message": "Internal server error"
}
Mon May 24 07:20:58 UTC 2021 : Lambda execution failed with status 200 due to customer function error: Object of type LambdaContext is not JSON serializable. Lambda request id: 32d4e450-576b-4bd6-abb9-d1bd893077ed
Mon May 24 07:20:58 UTC 2021 : Method completed with status: 502

context is not json format ? How can I see context in handler ?

If someone has opinion,please let me know

Thanks

1 Answers

You can print it and see if you want. It would be something like this:

LambdaContext([aws_request_id=7d78a745-bb86-42b8-89f0-389e9bdc3dcfe,log_group_name=/aws/lambda/mldx-devops-v1-TimeLambda-hINHLpDGpaNR,log_stream_name=2022/09/01/[$LATEST]0553dabc81194a57adf2a96775f88d02,function_name=mldx-devops-v1-TimeLambda-hINHLpDGpaNR,memory_limit_in_mb=128,function_version=$LATEST,invoked_function_arn=arn:aws:lambda:eu-west-1:187276065257:function:mldx-devops-v1-TimeLambda-hINHLpDGpaNR,client_context=None,identity=CognitoIdentity([cognito_identity_id=None,cognito_identity_pool_id=None])])
Related