At the moment I think I have a foundational misunderstanding of how to extract/pass data from lambda functions & I'm seeking clarification
Example: Let's say I want to pass some data to a lambda function ie {"hello":"world"}
and do so by passing data to that Lambda function by creating a REST endpoint in AWS API Gateway
At the moment I understand there are three ways to extract data:
1) event.queryStringParameters (makes sense)
ex. We can attach query parameters to the request URL: https://fakefakefake.execute-api.us-west-2.amazonaws.com/test/myapi?hello=world and in the lambda function:
const data = event.queryStringParameters.hello; // 'world'
2) event.body (makes sense & this is possible because of "Lambda Proxy Integration")
ex. If we attach the data in the body of the POST/PUT/etc request using Lambda Proxy Integration (ie forward all the data), we can access it via event.body
& within the lambda function (but making sure to JSON.parse the event.body since Lambda Proxy Integration will pass through stringified JSON & not valid/"real" JSON):
const parsedBody = JSON.parse(event.body); // should wrap in try/catch
const data = parsedBody.hello; // 'world'
3) Directly on the event object (Unclear)
ex. This case is unclear at the moment-- pass data to the lambda function from a REST endpoint setup in API Gateway where it is then accessible directly from the event object?
const data = event.hello; // 'world'
What is an example of how to pass data "directly" on the event object in a Lambda function like in case #3? I THINK this case requires that I create a "mapping template" when setting up the API/Lambda but I'm still unclear.
For a simple Node script, case 2 appears to have the "overhead" of parsing event body from stringified JSON so that's an understandable downside, but in addition to how to do it why or when would Case 3 be a more desirable approach?
Lambda proxy integration: Getting json body in aws Lambda via API gateway
Lambda proxy integration (AWS example): https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html
Lambda Proxy Integration vs Lambda Proxy (option #2 vs option #3 above): Lambda Integration vs. Lambda Proxy: Pros and Cons