What if debugging Lambda functions felt effortless?
You’re writing application logic, but half of the time is spent navigating AWS: deploying code, triggering test events, flipping between tabs, and digging through CloudWatch logs to see if that one-line change worked. It seems clunky and disconnected —and it’s nothing like how we write and debug regular application code.
Here’s how a typical development loop looks:
This approach is both time-consuming and distracting. Debugging a simple KeyError often means wading through log streams and deployment delays. Each deployment adds overhead, and that overhead slows down the feedback loop. And if the function talks to other AWS resources like DynamoDB or S3? The complexity multiplies.
Wouldn’t it be better if there were a way to debug AWS Lambda functions as if they were running locally, right inside an IDE, with breakpoints, test events, and direct feedback, just like any other code, even when they’re deployed in the cloud?
That’s exactly what the new AWS Toolkit for Visual Studio (VS) Code now makes possible.
Remote development in VS Code#
A significant enhancement has arrived that redefines how you develop AWS Lambda functions. With the latest release of the AWS Toolkit for Visual Studio Code, AWS now enables you to debug Lambda functions running in the cloud directly from a local IDE. This new capability means complex local emulation setups like SAM or Docker are no longer needed to step through the deployed code.
What does this feature mean for you?#
This feature is a fundamental shift in the serverless development workflow.
Previously, replicating the exact Lambda runtime environment locally, especially with cross-service integrations, was a major challenge. Developers often had to rely on console.log statements or repeatedly deploy their code.
With this new capability, you can now:
Set breakpoints: Pause execution at any point in the code and execute it line by line, understanding its flow and logic in detail.
Inspect variables: See the real-time values of the variables as the function runs in the cloud.
Simulate test events: Provide custom input payloads to trigger specific scenarios.
See real-time output: View function responses and logs directly within the local environment.
It supports Python, Node.js, and Java runtimes out of the box, and works whether you’re creating a function from scratch or editing one already deployed in the AWS account. This means fewer deploy-test-repeat cycles and more time focusing on the logic of the code.
Hands-on practice using VS Code with Lambda#
To truly understand the power and efficiency gains this new feature offers, we’ll walk you through how to use remote debugging with the AWS Toolkit for VS Code.
Prerequisites#
Before we begin, make sure the following are set up:
Visual Studio Code: If it’s not already installed, download it from https://code.visualstudio.com/ and follow the setup instructions for your OS.
AWS access keys: You’ll need a set of AWS access keys (Access Key ID and Secret Access Key) associated with an AWS account. The access keys must belong to an IAM user or role with sufficient permissions to interact with AWS Lambda. This includes listing, reading, updating, and invoking Lambda functions.
Note: Need help creating keys? Follow this step-by-step guide on generating AWS access keys.
The AWS Toolkit for VS Code empowers you across the entire Lambda development life cycle. Let’s explore this with two distinct scenarios:
How to quickly iterate on code locally before deployment
How to debug a deployed function in the cloud.
Installing and configuring the AWS Toolkit#
Before considering these scenarios, let’s review how to install and configure the AWS Toolkit in VS Code. Follow these steps to do that:
Open VS Code and click the “Extensions” icon on the left sidebar menu.
Search for “AWS Toolkit” and click the associated install button.
Now, let’s configure it for use by following these steps:
After installing the toolkit, a new “AWS” icon will appear on the left sidebar menu. Select the newly populated icon.
Open the options associated with the “Explorer” section of AWS Toolkit and select the “Connect to AWS” option.
Select the “Add New Connection” option.
Choose “IAM Credentials” as the sign-in option and click the “Continue” button.
Provide a profile name, AWS access key, and AWS secret key, and click the “Continue” button. You should see the “Explorer” section populate with your AWS resources.
This process is depicted in the slides below:
The AWS Toolkit is now configured with AWS credentials and can be used to perform AWS operations.
Now, let’s explore how to use this toolkit for developing and debugging code.
Demo scenario 1: Seamlessly shifting from Console to VS Code for code development#
This scenario focuses on the initial workflow of creating a Lambda function directly in the AWS Console and then transitioning to VS Code using the “Open in Visual Studio Code” button for remote invocation and minor edits.
Goal: Create a Lambda function in the AWS Management Console, bring its code into VS Code, and perform a basic remote invocation to confirm connectivity and functionality.
To achieve this seamless transition and initial remote invocation, follow these steps:
1. Create a Lambda function in the AWS Management Console#
Let’s begin by setting up a Lambda function directly within the AWS Management Console. This step mirrors a real-world scenario where a function might already exist or be initially configured via the console before deeper development in VS Code. To create the function, follow these steps:
Open the AWS Lambda console.
Click the “Create function” button.
On the “Create function” page, do the following:
Choose the “Author from scratch” option.
Provide
Demo_lambdaas the name of the Lambda function.Select a Python runtime like Python 3.13
Open the “Change default execution role” section and select an execution role for the Lambda function. This execution role should have the
AWSLambdaBasicExecutionRolepolicy attached as its permission policy. This policy allows the Lambda function to write create CloudWatch logs.
Once you’ve specified the configurations, click the “Create function” button.
2. Open the Lambda function code in VS Code#
Typically, we’d replace the default Lambda code with our own, deploy it, test it, and repeat the cycle if something breaks. Instead of that loop, we can open the function code directly in VS Code, run and test it locally, and only deploy once it’s working as expected.
Click the “Open in Visual Studio Code” button to open this code in VS Code. This button is usually found near the top right of the code editor pane within the Lambda console.
Your browser will prompt you to open VS Code. Confirm this action.
Note: VS Code might also prompt you to ask whether to allow the action being performed by the AWS Toolkit. If you see any such prompt, allow the action.
The AWS Toolkit for VS Code will launch and automatically download the Lambda function’s code into a temporary folder in the VS Code workspace, establishing a link to the deployed function. The function’s file (lambda_function.py for Python) is open in the editor.
You’ve got the Lambda function code in VS Code now. You can change it as needed, test it, and deploy it once you’re convinced it works.
Let’s say this is the Lambda function’s code that simply picks up the name from the input event and prints a message for it:
Once you’ve written this code in the lambda_function.py file, do the following to test it:
In the AWS Explorer sidebar in VS Code, navigate to the “Lambda” node.
Expand it to see the deployed Lambda functions. You should see
Demo_lambdafunction listed there.Right-click on
Demo_lambdain the AWS Explorer and select the “Invoke Remotely” option. A “Remote Invoke” configuration panel will appear.Leave “Enable Remote Debugging” unchecked for this basic invocation. (We’ll use it in the next scenario.)
Provide a test event payload. Let’s start with a simple one:
{}
Click the “Invoke” button.
Observe the “Output” panel in VS Code. You’ll see the function’s response (e.g., {"statusCode": 200, "headers": ..., "body": "\"Hello from your Console-created Lambda! No name provided.\""}) and any CloudWatch logs produced by the invocation streaming directly into the VS Code output.
This confirms that VS Code is communicating directly with the deployed Lambda function.
To demonstrate the rapid iteration capabilities, let’s make a minor code change directly in VS Code and deploy it back to the Lambda function.
In the
lambda_function.pyfile in VS Code, make a minor text change. For example, changeNo name provided.toName was missing.Once you’ve changed the code, invoke it remotely with {}, and you’ll see the updated message in the output, demonstrating the rapid iteration cycle directly from VS Code.
After you’ve made the required changes in the code and are satisfied with the result, simply save the changes VS Code file. You’ll be asked if you want these changes deployed in the Lambda function code. Select “Yes” to deploy these changes.
Demo scenario 2: Deep remote debugging and troubleshooting#
This scenario builds on the previous one, showing how the “Enable Remote Debugging” feature allows you to step through the deployed Lambda function’s code, inspect variables, and diagnose issues in real time within its cloud environment.
Goal: Leverage breakpoints and variable inspection to debug the Demo_lambda function running in AWS.
To effectively debug the deployed Lambda function in the cloud, follow these detailed steps:
Ensure
Demo_lambdais ready: Before we begin, confirm thatDemo_lambdahas been successfully deployed and is visible within the VS Code AWS Explorer from the previous demo.Set up breakpoints in the local code: To pause execution at specific points and inspect the code’s behavior, set breakpoints directly within your local Lambda function file.
Open the
lambda_function.pyfile forDemo_lambdain the VS Code editor.Set breakpoints at key lines, for example:
if event and isinstance(event, dict) and 'name' in event:message = f"Hello, {event['name']} from your Console-created Lambda!"print("No 'name' key found in the event payload.")
Initiate remote debugging: Start a remote invocation while enabling the debugging mode to connect the local VS Code debugger and the Lambda function running in AWS.
Right-click on
Demo_lambdain the AWS Explorer and select the “Invoke Remotely” option.The “Remote Invoke” configuration panel will appear.
Check the “Enable Remote Debugging” option.
Provide
{"name": "Debugger User"}as the test event payload.Click the “Invoke” button.
The AWS Toolkit will:
Temporarily modify the deployed Lambda function (e.g., adding a debugging agent, extending time-out).
Establish a secure debugging connection (often via AWS IoT Secure Tunneling).
Invoke the remote Lambda function with the provided test event.
The VS Code debugger will now activate, and execution will pause at the first breakpoint (
if event and isinstance(event, dict) and 'name' in event:).
Debug in the cloud environment: With the debugger paused, you can now interact with the Lambda function’s execution environment in real-time, as if running locally.
Inspect variables: In the “Run and Debug” view on the left (or hover over variables in the code), you can now see the real-time values of
event,context, and subsequentlynameandmessageas they are set within the cloud-running Lambda function.Step through code: Use the debugger controls (Step Over, Step Into, Step Out, Continue) to execute the code line by line. Observe how the execution flow follows the
ifcondition based on the input event.Observe CloudWatch logs: Watch the VS Code “Output” panel. CloudWatch logs generated by the
print()statements will stream in real time, intermingling with debugger messages to provide a comprehensive view.
Test a different scenario (without name): To fully understand the function’s behavior, test another input scenario and observe how the execution path changes during debugging.
Stop the debugging session (red square button in the debugger controls).
Right-click
Demo_lambdaagain in AWS Explorer and select the “Invoke Remotely” option.Ensure “Enable Remote Debugging” is still checked.
Provide
{}as the test event payload.Click the “Invoke” button.
Observe how the debugger pauses at the
ifstatement, but this time, when you step over, it willprint("No 'name' key found..."), demonstrating how you can quickly test different execution paths in the cloud.
Complete the debugging session: Once done debugging, the AWS Toolkit will automatically clean up the temporary configurations, returning the Lambda function to its normal operational state.
Continue stepping through the code or let it run to completion.
Once the remote invocation is finished, the AWS Toolkit will automatically clean up the temporary debugging configurations on the Lambda function, reverting it to its original state and ensuring the production environment is unaffected.
Local is indeed the new default#
Introducing remote debugging for AWS Lambda in VS Code is a monumental step forward for serverless developers. By enabling a powerful, integrated, and cloud-aware debugging experience, AWS has clarified that developing Lambda functions locally while leveraging the actual cloud environment is now the preferred and most efficient way to build.
To get more hands-on experience with the latest AWS tech, continue learning with the following cloud lab: