With any kind of http request, being it a simple web server or an api gateway, we will usually need to log different kind of information regarding the received request. But how can we do that with Lambda and how can we get all available information from it?
Thats when the event object comes in place. The API GATEWAY will send all information about the request encapsulated in the event object passing it as an argument to our lambda function, like this:
exports.handler = (event, context, callback) => { };
The event object have the following nested objects as shown below:
- 1. resource
- 2. path
- 3. httpMethod
- 4. headers
- 5. multiValueHeaders
- 6. queryStringParameters
- 7. multiValueQueryStringParameters
- 8. pathParameters
- 9. stageVariables
- 10. requestContext
- 11. body
- 12. isBase64Encoded
{ "resource": "/", "path": "/", "httpMethod": "GET", "headers": {}, "multiValueHeaders":{ "accept-encoding":[], "cookie":[], "Host":[], "User-Agent":[], "X-Amzn-Trace-Id":[], "X-Forwarded-For":[], "X-Forwarded-Port":[], "X-Forwarded-Proto":[], "x-real-ip":[] }, "queryStringParameters":{}, "multiValueQueryStringParameters":{}, "pathParameters":null, "stageVariables":null, "requestContext":{ "resourceId":"", "resourcePath":"", "httpMethod":"", "extendedRequestId":"", "requestTime":"", "path":"", "accountId":"", "protocol":"", "stage":"", "requestTimeEpoch":, "requestId":"", "identity":{ "cognitoIdentityPoolId":null, "accountId":null, "cognitoIdentityId":null, "caller":null, "sourceIp":"", "accessKey":null, "cognitoAuthenticationType":null, "cognitoAuthenticationProvider":null, "userArn":null, "userAgent":"", "user":null }, "body": null, "isBase64Encoded" } }
Comments
Post a Comment