The event data passed to Lambda contains the Instance ID.

You then need to call describe_tags() to retrieve a dictionary of the tags.

import boto3
client = boto3.client('ec2')

client.describe_tags(Filters=[
        {
            'Name': 'resource-id',
            'Values': [
                event['detail']['instance-id']
            ]
        }
    ]
)
Answer from John Rotenstein on Stack Overflow
🌐
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 - For example, AWS Lambda console uses the RequestResponse invocation type, so when you invoke the function on the console, the console will display the returned value. If the handler returns objects that can't be serialized by json.dumps, the runtime returns an error.
🌐
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
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:
Discussions

[deleted by user]
the answer is "historical reasons". but actually the value of a unified structure is unclear. why would you call the same lambda on different events? More on reddit.com
🌐 r/aws
28
17
December 22, 2022
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
amazon web services - AWS Lambda - Python : How to pass JSON input to event object in python handler - Stack Overflow
I have a lambda function with a lambda handler function. I want to pass a key via the 'event' object. That key can then be processed via this handler function. For example I want to pass a JSON inp... More on stackoverflow.com
🌐 stackoverflow.com
amazon web services - Navigating Event in AWS Lambda Python - Stack Overflow
So I'm fairly new to both AWS and Python. I'm on a uni assignment and have hit a road block. I'm uploading data to AWS S3, this information is being sent to an SQS Queue and passed into AWS Lambda. I More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/aws › [deleted by user]
Trying to better understand Lambda event objects (Python)
December 22, 2022 - Was it an async invocation that needs no response or is api gateway expecting a response object? ... I’ve got a lambda servicing 200,000 requests a month that maps to 1) SQS 2) SNS 3) DynamoDB, all with their own event formats. First thing my lambda does is rip the event open, see what the EventSource is and then pass the event off to a different in-lambda python function for each event source, each of those functions knows how to parse their own events and they all hand back a python object that I then interact with.
🌐
AWS Cloud Community
docs.powertools.aws.dev › lambda › python › latest › utilities › data_classes
Event Source Data Classes - Powertools for AWS Lambda (Python)
This example is based on the AWS Cognito docs for Verify Auth Challenge Response Lambda Trigger. app.pyCognito Verify Auth Challengen Example Event · The example integrates with Amazon Connect by handling contact flow events. The function converts the event into a ConnectContactFlowEvent object, providing a structured representation of the contact flow data.
🌐
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
You can use the interface definition for type hints, or to further inspect the structure of the Lambda context object. For the interface definition, see lambda_context.py · in the powertools-lambda-python repository on GitHub. The following example shows a handler function that logs context information. 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.
🌐
GeeksforGeeks
geeksforgeeks.org › cloud computing › lambda-function-handler-in-python
Lambda Function Handler In Python - GeeksforGeeks
July 23, 2025 - An event is generally a JSON Formatted String that contains the data that was passed by the external sources when invoking a Lambda function. It is usually of the 'dict' type in python but it can also be other types, such as 'list', 'int', 'float', ...
Find elsewhere
🌐
AWS Cloud Community
docs.powertools.aws.dev › lambda › python › 1.19.0 › utilities › data_classes
Event Source Data Classes - Lambda Powertools Python
The classes are initialized by passing in the Lambda event object into the constructor of the appropriate data class or by using the event_source decorator. For example, if your Lambda function is being triggered by an API Gateway proxy integration, you can use the APIGatewayProxyEvent class.
🌐
Medium
medium.com › @reach2shristi.81 › starting-your-lambda-journey-with-python-74d95346dd0
Starting your Lambda Journey with Python | by Min_Minu | Medium
June 25, 2023 - Here’s an example of a handler function: def lambda_handler(event, context): ... The event parameter provides the input data to your Lambda function. Extract relevant information from the event object and perform the required processing or logic.
🌐
PyPI
pypi.org › project › aws-lambda-event-handler
aws-lambda-event-handler · PyPI
This package provides a decorator for Python Lambda functions handling individual records in the event payload of the AWS Lambda function. ... The following demonstrates how to create a handler object that will be used as the entrypoint for various event sources that trigger a AWS Lambda invokation:
      » pip install aws-lambda-event-handler
    
Published   Aug 25, 2018
Version   0.0.3
🌐
Kevinhakanson
kevinhakanson.com › 2022-04-10-python-typings-for-aws-lambda-function-events
Python Typings for AWS Lambda Function Events | kevinhakanson.com
I was building a Python-based AWS Lambda function similar to what was announced by New – Use Amazon S3 Event Notifications with Amazon EventBridge and the code looked similar to this - full of “magic strings” that I had to discover. import boto3 def lambda_handler(event, context): bucket = event['detail']['bucket']['name'] file_key = event['detail']['object']['key'] s3 = boto3.client('s3') file_to_process = s3.get_object(Bucket=bucket, Key=file_key) Python has a module called typing that provides support for type hints, which make for a nice autocomplete experience in Visual Studio Code.
🌐
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?

🌐
Stack Overflow
stackoverflow.com › questions › 75220393 › aws-lambda-python-how-to-pass-json-input-to-event-object-in-python-handler
amazon web services - AWS Lambda - Python : How to pass JSON input to event object in python handler - Stack Overflow
Hence we can use event['who'] to fetch the value of the 'who' attribute. def lambda_handler(event, context): return { 'statusCode': 200, 'body': json.dumps('Hello from ' + event['who'] ) }
🌐
GitHub
gist.github.com › gene1wood › 24e431859c7590c8c834
A python AWS Lambda function which logs the contents of the event and context variables passed into the function. · GitHub
February 27, 2021 - A python AWS Lambda function which logs the contents of the event and context variables passed into the function. - log_aws_lambda_event_and_context.py
🌐
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 - This code imports the JSON Python package and defines a function named lambda_handler. This is important, as when an event trigger occurs, Lambda needs to know what to execute. This function entry point is defined in the Handler field. The format is filename.handler_name. In our example, the filename our code resides in is lambda_function.py.
🌐
Medium
medium.com › cyberark-engineering › aws-lambda-event-validation-in-python-now-with-powertools-431852ac7caa
AWS Lambda Event Validation in Python — Now with PowerTools | by Ran Isenberg | CyberArk Engineering | Medium
April 23, 2022 - Envelope is a class that knows ... this example, the EventBridge envelope will extract the model UserModel from the EventBridge schema, and trigger the handler with the parsed UserModel as the event parameter....
🌐
Kevinhakanson
kevinhakanson.com › 2022-08-06-refactoring-python-based-aws-lambda-functions-for-testing
Refactoring Python-based AWS Lambda functions for testing | kevinhakanson.com
The @validator decorated method is executed when constructing HitCounterEvent objects. The tests below use the unittest unit testing framework which look similar to other testing frameworks from other languages. from unittest import TestCase from src.hitcounter2.app import (HitCounterEvent, HitCounterResponse, lambda_handler) class TestHitCounterEventValidation(TestCase): def test_get_increment_default(self): event = HitCounterEvent(key="test") self.assertEqual(event.increment, 1) def test_get_increment_2(self): event = HitCounterEvent(key="test", increment=2) self.assertEqual(event.increment, 2) def test_get_increment_0(self): with self.assertRaises(ValueError): event = HitCounterEvent(key="test", increment=0)