aws lambda + http api with Payload Format Version 2.0. How to correctly parse the payload with Python 3.12 runtime
python - Lambda calling Lambda - how to access the payload in the second? - Stack Overflow
amazon web services - How to access the event object with python in AWS Lambda? - Stack Overflow
What fields/properties do 'event' and 'context' have in a Python Lambda invoked by API Gateway?
Videos
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']
]
}
]
)
In the Details Section of the Event, you will get the instance Id's. Using the instance id and AWS SDK you can query the tags. The following is the sample event
{
"version": "0",
"id": "ee376907-2647-4179-9203-343cfb3017a4",
"detail-type": "EC2 Instance State-change Notification",
"source": "aws.ec2",
"account": "123456789012",
"time": "2015-11-11T21:30:34Z",
"region": "us-east-1",
"resources": [
"arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1111"
],
"detail": {
"instance-id": "i-abcd1111",
"state": "running"
}
}
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 responseObjectI 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?
» pip install aws-lambda-event-handler