Assuming you are using a proxy integration the event looks like this: https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html#apigateway-example-event The context object: https://docs.aws.amazon.com/lambda/latest/dg/python-context.html Answer from chrisdubya555 on reddit.com
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › using the lambda context object to retrieve python function information
Using the Lambda context object to retrieve Python function information - AWS Lambda
import time def lambda_handler(event, context): print("Lambda function ARN:", context.invoked_function_arn) print("CloudWatch log stream name:", context.log_stream_name) print("CloudWatch log group name:", context.log_group_name) print("Lambda Request ID:", context.aws_request_id) print("Lambda function memory limits in MB:", context.memory_limit_in_mb) # We have added a 1 second delay so you can see the time remaining in get_remaining_time_in_millis. time.sleep(1) print("Lambda time remaining in MS:", context.get_remaining_time_in_millis()) In addition to the options listed above, you can also use the AWS X-Ray SDK for Instrumenting Python code in AWS Lambda to identify critical code paths, trace their performance and capture the data for analysis.
🌐
GitHub
gist.github.com › gene1wood › c0d37dfcb598fc133a8c
Details on the AWS Lambda Python LambdaContext context object when instantiated from a CloudFormation stack · GitHub
The Python runtime does not have ... · def lambda_handler(event, context): if event['variable_name'] == 1: return { 'message' : 'We are done' } else: raise Exception('Sending failure')...
Discussions

What fields/properties do 'event' and 'context' have in a Python Lambda invoked by API Gateway?
Assuming you are using a proxy integration the event looks like this: https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html#apigateway-example-event The context object: https://docs.aws.amazon.com/lambda/latest/dg/python-context.html More on reddit.com
🌐 r/aws
4
3
September 23, 2022
python - How to invoke AWS lambda function with context argument - Stack Overflow
I built my lambda function using python with the standard required format def lambda_handler(event, context): When I run it, everything is fine except I get all the info I call in the logs because... More on stackoverflow.com
🌐 stackoverflow.com
python - How can I import LambdaContext? - Stack Overflow
I have experimented with @Dmitry-Masanov 's answer, and have bodged a python fixture for pytest, which can be used either in the test script itself, or as I am doing, in the conftest.py file. @pytest.fixture def mock_lambda_context(): class ClientContext: """ Class for mocking Context Has `custom`, ... More on stackoverflow.com
🌐 stackoverflow.com
python - Use context manager in lambda, how? - Stack Overflow
See Python Try Catch Block inside lambda. Your only option is to stick to using a proper function instead. ... Like this for example. Is there a problem with that in case of raised exceptions or something? ... Ah, I forgot about that one. ContextDecorator is not part of the lambda expression. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Readthedocs
aws-lambda-for-python-developers.readthedocs.io › en › latest › 02_event_and_context
Chapter 2: What is the event & context? - AWS Lambda for Python Developers
Now let's look at the event, context and return value individually. event is the data that's passed to the function upon execution. In the previous chapter, we used the console to create a test event to be passed to the Lambda Function. In real-life, the event can come from whatever triggers the lambda, a good example, if the lambda were triggered from an HTTP api call via API Gateway, then the event object would look something like this:
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python › define lambda function handler in python
Define Lambda function handler in Python - AWS Lambda
January 31, 2026 - The context object is a Python ... method on the context object. For example, the following code snippet assigns the value of the aws_request_id property (the identifier for the invocation request) to a variable named request....
🌐
Reddit
reddit.com › r/aws › what fields/properties do 'event' and 'context' have in a python lambda invoked by api gateway?
r/aws on Reddit: What fields/properties do 'event' and 'context' have in a Python Lambda invoked by API Gateway?
September 23, 2022 -

I am writing a Python Lambda that will be invoked via HTTP. A web service will make an HTTP call to an API Gateway resource that I define, which will then invoke the Lambda. My Lambda handler will look like:

def lambda_handler(event, context):
    // do stuff down here
    return responseObject

I am trying to find documentation on event and context so I know how to do things like:

  • extract query string parameters from requests

  • extract path parameters from requests

  • inspect the request entity

  • etc.

Surprising I can find no official AWS documentation on what fields/properties these two objects have on them when they are invoked from an API Gateway resource action. I found this article which was sort of helpful but nothing official from AWS. Can anyone point me in the right direction?

Top answer
1 of 4
4

You could try using LocalStack:

LocalStack provides an easy-to-use test/mocking framework for developing Cloud applications.

Currently, the focus is primarily on supporting the AWS cloud stack.

LocalStack spins up the following core Cloud APIs on your local machine:

API Gateway at http://localhost:4567

Kinesis at http://localhost:4568

DynamoDB at http://localhost:4569

DynamoDB Streams at http://localhost:4570

Elasticsearch at http://localhost:4571

S3 at http://localhost:4572

Firehose at http://localhost:4573

Lambda at http://localhost:4574

SNS at http://localhost:4575

SQS at http://localhost:4576

Redshift at http://localhost:4577

ES (Elasticsearch Service) at http://localhost:4578

SES at http://localhost:4579

Route53 at http://localhost:4580

CloudFormation at http://localhost:4581

CloudWatch at http://localhost:4582

2 of 4
4

class LambdaContext defined in /var/runtime/awslambda/bootstrap.py which is used to launch users functions and has the following structure:

class LambdaContext(object):
    def __init__(self, invokeid, context_objs, client_context, invoked_function_arn=None):
        self.aws_request_id = invokeid
        self.log_group_name = os.environ['AWS_LAMBDA_LOG_GROUP_NAME']
        self.log_stream_name = os.environ['AWS_LAMBDA_LOG_STREAM_NAME']
        self.function_name = os.environ["AWS_LAMBDA_FUNCTION_NAME"]
        self.memory_limit_in_mb = os.environ['AWS_LAMBDA_FUNCTION_MEMORY_SIZE']
        self.function_version = os.environ['AWS_LAMBDA_FUNCTION_VERSION']
        self.invoked_function_arn = invoked_function_arn

        self.client_context = make_obj_from_dict(ClientContext, client_context)
        if self.client_context is not None:
            self.client_context.client = make_obj_from_dict(Client, self.client_context.client)
        self.identity = make_obj_from_dict(CognitoIdentity, context_objs)

    def get_remaining_time_in_millis(self):
        return lambda_runtime.get_remaining_time()

    def log(self, msg):
        str_msg = str(msg)
        lambda_runtime.send_console_message(str_msg, byte_len(str_msg))

If you want to emulate it on your local environment, just add it into your script:

class ClientContext(object):
    __slots__ = ['custom', 'env', 'client']


def make_obj_from_dict(_class, _dict, fields=None):
    if _dict is None:
        return None
    obj = _class()
    set_obj_from_dict(obj, _dict)
    return obj


def set_obj_from_dict(obj, _dict, fields=None):
    if fields is None:
        fields = obj.__class__.__slots__
    for field in fields:
        setattr(obj, field, _dict.get(field, None))


class LambdaContext(object):
    def __init__(self, invokeid, context_objs, client_context, invoked_function_arn=None):
        self.aws_request_id = invokeid
        self.log_group_name = os.environ['AWS_LAMBDA_LOG_GROUP_NAME']
        self.log_stream_name = os.environ['AWS_LAMBDA_LOG_STREAM_NAME']
        self.function_name = os.environ["AWS_LAMBDA_FUNCTION_NAME"]
        self.memory_limit_in_mb = os.environ['AWS_LAMBDA_FUNCTION_MEMORY_SIZE']
        self.function_version = os.environ['AWS_LAMBDA_FUNCTION_VERSION']
        self.invoked_function_arn = invoked_function_arn

        self.client_context = make_obj_from_dict(ClientContext, client_context)
        if self.client_context is not None:
            self.client_context.client = None
        self.identity = None


    def get_remaining_time_in_millis(self):
        return None

    def log(self, msg):
        str_msg = str(msg)
        print(str_msg)
        # lambda_runtime.send_console_message(str_msg, byte_len(str_msg))
Find elsewhere
🌐
PyPI
pypi.org › project › aws-lambda-context
aws-lambda-context
December 3, 2018 - JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
AWS Cloud Community
docs.powertools.aws.dev › lambda › python › latest › utilities › typing
Typing - Powertools for AWS Lambda (Python)
All examples shared in this documentation are available within the project repository. We provide static typing for any context methods or properties implemented by Lambda context object.
🌐
GitHub
github.com › aws-powertools › powertools-lambda-python › blob › develop › aws_lambda_powertools › logging › lambda_context.py
powertools-lambda-python/aws_lambda_powertools/logging/lambda_context.py at develop · aws-powertools/powertools-lambda-python
Full Lambda Context object: https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html · · Parameters · ---------- function_name: str · Lambda function name, by default "UNDEFINED" e.g. "test" function_memory_size: int ·
Author   aws-powertools
🌐
Orchestra
getorchestra.io › guides › context-in-aws-lambda-3
Context in AWS lambda | Orchestra
September 10, 2024 - One of the key elements of building effective serverless applications with Lambda is understanding the Context object, which provides useful information about the function's execution environment. In this guide, we’ll explore the context object and how to leverage it in AWS Lambda using Python.
🌐
Real Python
realpython.com › python-lambda
How to Use Python Lambda Functions – Real Python
December 1, 2023 - In January 1994, map(), filter(), reduce(), and the lambda operator were added to the language. Here are a few examples to give you an appetite for some Python code, functional style. The identity function, a function that returns its argument, is expressed with a standard Python function definition using the keyword def as follows: ... Note: In the context ...
🌐
Pydantic
pydantic.dev › articles › lambda-intro
AWS Lambda: Validate event & context data via Pydantic
April 4, 2024 - Practical guide with step-by-step instructions for validating event and context data in AWS Lambda functions using Pydantic
🌐
Stack Overflow
stackoverflow.com › questions › 35489878 › how-to-access-context-identity-from-a-python-aws-lambda-function
amazon web services - How to access context.identity from a Python AWS Lambda function? - Stack Overflow
With these additions, when the lambda function is called its `context.identity' parameter will be populated with the values of the caller's cognity identifier pool and id. From Python in your Lambda function be sure to access with context.identity and not context[identity]
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with python
Building Lambda functions with Python - AWS Lambda
The version of the AWS SDK included in the Python runtime depends on the runtime version and your AWS Region. To find the version of the SDK included in the runtime you're using, create a Lambda function with the following code. import boto3 import botocore def lambda_handler(event, context): print(f'boto3 version: {boto3.__version__}') print(f'botocore version: {botocore.__version__}')
🌐
GeeksforGeeks
geeksforgeeks.org › cloud computing › lambda-function-handler-in-python
Lambda Function Handler In Python - GeeksforGeeks
July 23, 2025 - In the menu you will get a lot of runtime options to select, but we will choose python 3.12 as the runtime. Step 5: Click on the 'Create function' after setting all things up. After this you will be redirected into your function console where you can configure your lambda function and add your code. In this console you will also notice an editor with lambda_handler.py file. This is your function's main code. Here is the default format of the lambda_function.py file. ... import json def lambda_handler(event, context): # TODO implement return { 'statusCode': 200, 'body': json.dumps('Hello from Lambda!') }
🌐
Stackify
stackify.com › aws-lambda-with-python-a-complete-getting-started-guide
AWS Lambda with Python: A Complete Getting Started Guide - Stackify
May 16, 2024 - Set this drop-down to the correct value of Python 3.7. Now go ahead and click the Create function button, which will bring you to the function configuration screen. This can be a bit overwhelming at first, but we’ll briefly cover a few of the essentials here. Also Read-https://stackify.com/aws-lambda-with-node-js-a-complete-getting-started-guide/