DEV Community

Discussion on: Exploring the Inner Workings of SST Live Lambda

Collapse
 
aimanparvaiz profile image
Aiman Parvaiz

Very interesting post. I was missing the part of how the local lambda is executed and payload is passed to stub lambda.

When you run sst dev, it deploys your app and replaces the Lambda functions with a stub version.
It also starts up a local WebSocket client and connects to your AWS accounts' IoT endpoint.
Now, when a Lambda function in your app is invoked, it publishes an event, where the payload is the Lambda function request.
Your local WebSocket client receives this event. It publishes an event acknowledging that it received the request.
Next, it runs the local version of the function and publishes an event with the function response as the payload. The local version is run as a Node.js Worker.
Finally, the stub Lambda function receives the event and responds with the payload.