I have a simple API Gateway setup right now with three routes - $connect, $disconnect, OnMessage
. Each of them trigger a different Lambda function.
The Lambda function is the default one:
exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'), // Varies for each Lambda function
};
return response;
};
Except the JSON.stringify
part is different for the three routes.
Right now all I'm trying to do is connect to the API Gateway's websocket URL and trigger the functions. I am able to connect to the websocket and CloudWatch also logs the three triggers correctly so I know that aspect is working.
But when I check the logs, the Endpoint Response before Transformation
is the same for all three:
It should be "Hello from Lambda"
only for $connect
's log.
The metrics under Monitor
in the Lambda console reflect the functions triggering accurately but the response returned is not the right one.
How do I fix this?
Am I understanding the CloudWatch logs wrongly or is there a specific setting or setup I need to do to get accurate results?
Any pointers regarding this will be helpful.
Edit:
I changed $connect
's Lambda function and it turns out that the response in CloudWatch logs is not from this Lambda function. The endpoint response is just the default Lambda function.
Like the comment above pointed out, it had to do with deploying the Lambda functions. I thought the API was the only thing we deploy but we also need to deploy the Lambda functions to get them to work properly.