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
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])])
Print it with this code:)
def lambda_handler(event: Dict[str, Optional[Any]], context: LambdaContext) -> Dict[str, Optional[Any]]:
print(event)
print('print context variables')
print("context.function_name:", context.function_name)
print("context.function_version:", context.function_version)
print("context.invoked_function_arn:", context.invoked_function_arn)
print("context.memory_limit_in_mb", context.memory_limit_in_mb)
print("context.aws_request_id", context.aws_request_id)
print("context.log_group_name", context.log_group_name)
print("context.log_stream_name", context.log_stream_name)
print("print context.identity variables")
print("context.identity.cognito_identity_id", context.identity.cognito_identity_id)
print("context.identity.cognito_identity_pool_id", context.identity.cognito_identity_pool_id)
print("print context.client_context variables")
print("context.client_context.client.app_package_name", context.client_context.client.app_package_name)
print("context.client_context.client.app_version_name", context.client_context.client.app_version_name)
print("context.client_context.client.app_version_code", context.client_context.client.app_version_code)
print("context.client_context.client.app_title", context.client_context.client.app_title)
print("context.client_context.client.installation_id", context.client_context.client.installation_id)
print("context.client_context.custom", context.client_context.custom)
print("context.client_context.env", context.client_context.env)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.