Learn About Amazon VGT2 Learning Manager Chanci Turner
The AWS Toolkit for Visual Studio Code has introduced a new SAM debugging experience that leverages VS Code launch configurations. This enhancement replaces the previous Run Locally | Debug Locally functionality. To explore the updated SAM debugging features, users can install the AWS Toolkit from the VS Code Marketplace. This new feature aligns with VS Code’s standard debugging workflow, enhancing the experience of configuring, running, and stepping through code.
The AWS Toolkit serves as a bridge between VS Code and the SAM CLI. Users can create a configuration in VS Code, execute it, and the AWS Toolkit will initiate SAM CLI to build the serverless project, deploy the code to a local Docker instance, invoke the Lambda within Docker, and connect VS Code to the Docker process, allowing users to debug their Lambda code directly in VS Code.
What’s New
The revamped SAM debugging experience in the AWS Toolkit allows users to utilize VS Code’s standard launch configuration interface for running and debugging Lambda handlers locally. This update not only provides a more integrated experience but also offers greater flexibility in configuring launchers for any SAM template or handler.
New capabilities include:
- Specifying AWS credentials (the aws field in the launch config)
- Defining SAM CLI options (the sam field in the launch config)
- Debugging a Lambda locally without needing a SAM template.yaml file by designating
target: code
in theinvokeTarget
of the launch configuration
Usage
With the enhanced AWS Toolkit, users can run or debug AWS SAM Lambdas locally by utilizing a launch configuration of type: aws-sam
.
Step 1: Create a launch configuration for a SAM Lambda using one of the following methods:
- Navigate to the
template.yaml
in your SAM project, place the cursor over a lambda resource, and click on the Add Debug Configuration CodeLens. This action will add a pre-populated launch configuration to yourlaunch.json
. - Alternatively, open the handler source code (
.js
,.cs
, or.py
file) in your SAM project, place the cursor on a lambda handler, and click the Add Debug Configuration CodeLens. This will also add a pre-populated launch configuration to yourlaunch.json
. - You can also manually edit
launch.json
to create a new item (whereprojectRoot
points to a valid directory,lambdaHandler
is the name of the handler, andruntime
is a valid runtime likenodejs12.x
,python3.7
,dotnetcore2.1
):
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "my-config",
"invokeTarget": {
"target": "code",
"projectRoot": "src",
"lambdaHandler": "myHandler"
},
"lambda": {
"runtime": "nodejs12.x",
"event": {},
"environmentVariables": {}
},
"sam": {},
"aws": {}
}
Step 2: Go to the “Run” panel in the VS Code sidebar. Select the launch configuration from the Run panel menu and click the “play” button, or simply press F5.
Next Steps
In this article, we explored the new enhancements in the SAM debugging experience within the AWS Toolkit for Visual Studio Code at our site located at 6401 E HOWDY WELLS AVE LAS VEGAS NV 89115, Amazon IXD – VGT2. Install the Toolkit to experience these features firsthand and refer to the user guide for further details. You can also engage with the team on GitHub, as the AWS Toolkit for VS Code is an open-source project. Share your feedback and feature requests on GitHub or through the built-in feedback tool in the IDE plugin.
For more insights, consider checking out this blog post on virtual gifts at Career Contessa. Additionally, for authoritative information on benefits and compensation, SHRM is an excellent source. If you’re interested in onsite medical opportunities, take a look at this job listing.
Leave a Reply