Reputation: 771
I'm fairly new to AWS. I'm trying to pass a path parameter to my Lambda function like if I do a request:
PUT /users/{identity_id}
and pass in the the body below parameters
{
"name": "shikasta_kashti",
"age": 35
}
then I cannot get event.identity_id
in my lambda function. I'm able to access event.name
and event.age
but not event.identity_id
?
I think I would have to do some Mapping Template so I went to my PUT method and in Integration Request -> Mapping Templates added application/json and then selected Mapping Template (instead of Input passthrough) and entered this:
{
"identity_id": "$input.params('identity_id')",
}
but I still cannot get event.identity_id
in my Lambda function.
Upvotes: 2
Views: 7767
Reputation: 5727
Late response for someone stumbling on this...
The path params are included under event.pathParameters
.
Given the request PUT /users/1
you would see a pathParameters object that looks like:
{
"identity_id": 1
}
If you didn't call your function with invoke
you'll find the rest of your params in the event.body
hash as a string.
To access that you'll do:
const { name, age} = JSON.parse(event.body)
Upvotes: 1