I have an AWS Lambda function written in Node.js that logs the event and returns it in the response. When I test this function using the AWS API Gateway test feature, it works perfectly and returns the full event object. However, when I test it with Postman, the event object appears empty in the response. Here is the code for the Lambda function:
export const handler = async (event, context, callback) => {
// Log the headers to CloudWatch
console.log('Received events:', event);
// Create a response object containing the headers
const response = {
statusCode: 200,
body: JSON.stringify(event, null, 2), // Pretty-print the JSON
};
// Return the response
return response;
};
When tested with the AWS API Gateway, the response looks like this:
{
"statusCode": 200,
"body": "{n "version": "2.0",n "routeKey": "$default",n "rawPath": "/path/to/resource",n "rawQueryString": "parameter1=value1¶meter1=value2¶meter2=value",n "cookies": [n "cookie1",n "cookie2"n ],n "headers": {n "Header1": "value1",n "Header2": "value1,value2"n },n "queryStringParameters": {n "parameter1": "value1,value2",n "parameter2": "value"n },n "requestContext": {n "accountId": "123456789012",n "apiId": "api-id",n "authentication": {n "clientCert": {n "clientCertPem": "CERT_CONTENT",n "subjectDN": "www.example.com",n "issuerDN": "Example issuer",n "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1",n "validity": {n "notBefore": "May 28 12:30:02 2019 GMT",n "notAfter": "Aug 5 09:36:04 2021 GMT"n }n }n },n "authorizer": {n "jwt": {n "claims": {n "claim1": "value1",n "claim2": "value2"n },n "scopes": [n "scope1",n "scope2"n ]n }n },n "domainName": "id.execute-api.us-east-1.amazonaws.com",n "domainPrefix": "id",n "http": {n "method": "POST",n "path": "/path/to/resource",n "protocol": "HTTP/1.1",n "sourceIp": "192.168.0.1/32",n "userAgent": "agent"n },n "requestId": "id",n "routeKey": "$default",n "stage": "$default",n "time": "12/Mar/2020:19:03:58 +0000",n "timeEpoch": 1583348638390n },n "body": "eyJ0ZXN0IjoiYm9keSJ9",n "pathParameters": {n "parameter1": "value1"n },n "isBase64Encoded": true,n "stageVariables": {n "stageVariable1": "value1",n "stageVariable2": "value2"n }n}"
}
However, when I test with Postman, the response is:
curl --location 'https://site.amazonaws.com/beta/KlikyTestAPI'
--header 'Content-Type: application/json'
--header 'Accept: application/json'
--header 'Authorization: ••••••'
Postman Response:
{
"statusCode": 200,
"body": "{}"
}
I don’t why is empty
Need help to resolve this