🌐
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
When Lambda runs your function, it passes a context object to the handler. This object provides methods and properties that provide information about the invocation, function, and execution environment.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with typescript › using the lambda context object to retrieve typescript function information
Using the Lambda context object to retrieve TypeScript function information - AWS Lambda
When Lambda runs your function, it passes a context object to the handler . This object provides methods and properties that provide information about the invocation, function, and execution environment.
🌐
GitHub
gist.github.com › gene1wood › c0d37dfcb598fc133a8c
Details on the AWS Lambda Python LambdaContext context object when instantiated from a CloudFormation stack · GitHub
Alexa's skill id is delivered the context object during certain audio playback requests. does that have an alias? ... Just found this, but for anyone else looking, AWS Lambda's Python runtime does not have a succeed() capability.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › using the lambda context object to retrieve node.js function information
Using the Lambda context object to retrieve Node.js function information - AWS Lambda
When Lambda runs your function, it passes a context object to the handler . This object provides methods and properties that provide information about the invocation, function, and execution environment.
🌐
Orchestra
getorchestra.io › guides › context-in-aws-lambda
Context in AWS lambda | Orchestra
March 22, 2025 - In AWS Lambda, the context object is a key component that provides runtime information about the Lambda function's execution. It is passed as a parameter to the Lambda handler function and contains useful data that can help manage function behavior, ...
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with java › using the lambda context object to retrieve java function information
Using the Lambda context object to retrieve Java function information - AWS Lambda
The function logs the class type of the incoming event before returning null. ... library. You can implement this interface to create a context class for testing. The following example shows a context class that returns dummy values for most properties and a working test logger. package example; import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.CognitoIdentity; import com.amazonaws.services.lambda.runtime.ClientContext; import com.amazonaws.services.lambda.runtime.LambdaLogger; public class TestContext implements Context{ public TestContext() {}
🌐
AWS Cloud Community
docs.powertools.aws.dev › lambda › python › latest › utilities › typing
Typing - Powertools for AWS Lambda (Python)
Using LambdaContext typing makes it possible to access information and hints of all properties and methods implemented by Lambda context object.
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with go › using the lambda context object to retrieve go function information
Using the Lambda context object to retrieve Go function information - AWS Lambda
In Lambda, the context object provides methods and properties with information about the invocation, function, and execution environment. When Lambda runs your function, it passes a context object to the handler . To use the context object in your handler, you can optionally declare it as an ...
Top answer
1 of 3
30

Event represents the event or trigger that caused the invocation of the lambda. For example, if your lambda is triggered by an upload to S3 this will contain information about the object being uploaded for example:

    {
      "Records": [
        {
          "eventVersion": "2.0",
          "eventTime": "1970-01-01T00:00:00.000Z",
          "requestParameters": {
            "sourceIPAddress": "127.0.0.1"
          },
          "s3": {
            "configurationId": "testConfigRule",
            "object": {
              "eTag": "0123456789abcdef0123456789abcdef",
              "sequencer": "0A1B2C3D4E5F678901",
              "key": "HappyFace.jpg",
              "size": 1024
            },
            "bucket": {
              "arn": bucketarn,
              "name": "sourcebucket",
              "ownerIdentity": {
                "principalId": "EXAMPLE"
              }
            },
            "s3SchemaVersion": "1.0"
          },
          "responseElements": {
            "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH",
            "x-amz-request-id": "EXAMPLE123456789"
          },
          "awsRegion": "us-east-1",
          "eventName": "ObjectCreated:Put",
          "userIdentity": {
            "principalId": "EXAMPLE"
          },
          "eventSource": "aws:s3"
        }
      ]
    }

Here is detailed information about events, with an example.

Context Provides information about the invocation, function, and execution environment of your lambda. So you can use this to check the memory allocation or to retrieve the number of milliseconds left before the execution times out. Here is detailed documentation about context, with an example.

2 of 3
3

From the docs

When Lambda runs your function, it passes a context object to the handler. This object provides methods and properties that provide information about the invocation, function, and execution environment.

Event (and the args) are described here.

To put it more simply, think of event as an input to a regular function. Context is an extra input supplied by AWS to give you a variety of meta context and such.

Find elsewhere
🌐
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))
🌐
DEV Community
dev.to › cfjps › what-is-the-lambda-execution-context-and-why-use-it-3i0b
What is the Lambda Execution context and why use it? - DEV Community
August 14, 2021 - When your Lambda function gets ... runtime environment. The execution context is a temporary runtime environment that initializes any external dependencies of your lambda code....
🌐
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
🌐
Sentry
docs.sentry.io › platforms › node › guides › aws-lambda › enriching-events › context
Enriching Events | Sentry for AWS Lambda
Context is a way to add additional metadata to events. While you cannot filter by contexts in the Sentry UI, context information is displayed in the event details.
🌐
Michaelbrewer
michaelbrewer.github.io › aws-lambda-events › lambda-context
Lambda Context - AWS Lambda Events
When Lambda runs your function, it passes a context object to the handler.
🌐
Go Packages
pkg.go.dev › github.com › aws › aws-lambda-go › lambdacontext
lambdacontext package - github.com/aws/aws-lambda-go/lambdacontext - Go Packages
March 2, 2026 - This package allows Lambda functions to access metadata about the current invocation, including request ID, function ARN, Cognito identity, and client context.
🌐
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
But we'll learn in later chapters how you can provide lambda any number of .py files as your code, and then specify the handler using the following convention: ... Handler functions must always take two arguments, event and context, and they may return a value, in short they always have to look like this:
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with c# › using the lambda context object to retrieve c# function information
Using the Lambda context object to retrieve C# function information - AWS Lambda
When Lambda runs your function, it passes a context object to the handler . This object provides properties with information about the invocation, function, and execution environment.