Running and debugging Serverless Framework Python Lambda functions locally in VSCode ☁️

For serverless development, I believe you need to have the ability to run and debug individual functions locally.
Serverless Framework has a useful feature for doing just that: the invoke local command.
The issue I have found is while it works for Node.js functions, I have never been able to get serverless invoke local
working with VSCode’s excellent Python debugging tools.
There are some great guides available for setting up VSCode to debug Node.js Lambda functions managed by Serverless Framework, but I have not seen many for Python, possibly due to the faff of creating a debugging setup that uses a Node.js script to invoke a Python runtime.
This guide explains how I run and debug my Python Lambda functions locally. My solution makes use of AWS SAM and the AWS Toolkit for VSCode.
Why not just use AWS SAM in place of Serverless Framework (SF) then, I hear some of you asking? Well, for one, I use SF at my work. SF has grown on me, too. It’s a mature, battle tested platform at this point, and its plugin ecosystem provides all sorts of extra functionality for many different use cases not explicitly supported out the box. I am able to leverage the best parts of SF and AWS SAM together.
This setup allows me to do proper local step-through debugging of my Lambda functions by setting breakpoints, inspecting variables, and executing function code one line at a time, while still communicating with real, deployed AWS resource - just as the function would do in a real invocation.
Prerequisites
I am assuming you have Serverless Framework already installed, you use it to manage and deploy Python Lambda functions to AWS, and you use VSCode with the Python extension.
Steps
- Install the AWS SAM CLI.
- Install the AWS Toolkit for VSCode.
- Add the below launch profile to your
.vscode/launch.json
. - Run and debug as normal! Further config can be found here.
A few things to note
- AWS Toolkit expects a
requirements.txt
in your workspace folder. I use Poetry to manage my project dependencies, so I have apreLaunchTask
(shown below) that generates one automatically before debugging. You can even add apostDebugTask
. Read more about VSCode tasks here.
- I use named profiles when interacting with the AWS CLI, which you specify in the
aws
field. - Function
environmentVariables
andpayload
s can also easily be customised. - You can pass additional runtime debug arguments this way.
That should be all you need to get started! 👟

Any feedback? Do you know of way to get sls invoke local
playing nice with Python and VSCode’s debugging? Have an alternative solution or just think this is completely stupid? Let me know in the comments!