AWS Lambda is introducing an enhanced local IDE experience to simplify Lambda-based application development. The new features help developers to author, build, debug, test, and deploy Lambda applications more efficiently in their local IDE when using Visual Studio Code (VS Code).
Overview The IDE experience is part of the AWS Toolkit for Visual Studio Code. A new guided walkthrough helps developers set up their local environment and install required tools. The toolkit includes a set of sample applications which show you how to iterate on your code locally and in the cloud. You can configure and save build settings to speed up application builds. Generate a configuration file to set up the debugging environment for VS Code to attach and launch the step-through debugger. Iterate faster by choosing to sync local application changes quickly to the cloud or perform a full application deploy. Test functions locally and in the cloud and create and share test events to speed up local and cloud testing. There are quick action buttons for build, deploy to cloud, and local or remote invoke. The toolkit integrates with AWS Infrastructure Composer, providing a visual application building experience directly from the IDE.
Using the new features Installing the extension To use the updated IDE experience, ensure you have the AWS Toolkit minimum version 3.31.0 installed as a VS Code Extension.
The AWS Toolkit now includes an additional section called Application Builder within the AWS extension side-bar. This allows you to view template resources and create, build, debug, and test serverless applications.
Using Application Builder for existing applications You can open an existing local application template using Open Folder.
Lambda’s enhanced in-console editing experience allows you to download existing function code and an AWS Serverless Application Model (AWS SAM) template. This allows you to start in the console and more easily move to using infrastructure as code, which is a serverless best practice.
Using the guided walkthrough The guided walkthrough helps you install dependencies, select an application template, and explains how to use Application Builder to iterate locally and deploy to the cloud.
Complete installation takes you through a wizard to install required dependencies and select application templates. The wizard provides download links to install the three dependencies:
AWS Command Line Interface (AWS CLI)
If you have installed the dependencies, selecting the links recognizes the installations.
Creating an application from the samples The following steps show how to create a function locally from an included template. You build the code artifact, locally test and debug, deploy, and remotely invoke and view results and logs, all without leaving your IDE.
There are also two specific example applications to explore Lambda functionality.
Building a synchronous Rest API application 1. Select Rest API and chose Initialize your project.
2. Select a language runtime. Select Python for this example.
3. Open the file explorer, create a folder to download the example application and choose Create Project.
Application Builder downloads the application. This includes the function code hello_world\app.py, with dependencies in requirements.txt, an AWS SAM template, template.yaml file, and an example event trigger, event.json. A README.md file explains the application structure and provides build and deploy instructions.
The Application Builder section populates with the template resources.
Building the application The build step helps you build artifacts from the files in your application project directory.
samconfig.toml.version = 0.1[default.build.parameters]template_file = "c:\\Code\\lambda-dx\\Rest-API\\template.yaml"cached = trueparallel = trueuse_container = true
AWS SAM builds the application. It downloads the build container image, installs the dependencies, and copies the function code.
Iterate locally: invoke and debug You can locally invoke and debug your serverless application before uploading it to the cloud. This helps you to test the logic of your function faster. Step-through debugging allows you to identify and fix issues in your application one instruction at a time in your local environment.
Local invoke 1. In the Application Builder section, navigate to the function and select Local Invoke and Debug Configuration. Initiating Local Invoke and Debug Configuration
This brings up another window which allows you to configure how to invoke the function locally and set up a debug configuration. Viewing Local Invoke and Debug Configuration Options
You can create sample event payloads to test your function. Select an event provides a list of common trigger event payloads you can use and customize. Selecting an example event template
This example application has an included sample event.
events\event.json file.Select the Invoke button. This builds the application and locally invokes the function within a Lambda emulation environment, using the event input file.
View the function output within the IDE Output pane.
Viewing function output
Local debugging You can also debug the function locally using VS Code’s built-in debugger.
Add a breakpoint to the function code. Adding a breakpoint to the function code
Select the Invoke button again. This locally invokes the function and attaches a debugger to the Lambda emulation environment.
The debugger stops at the breakpoint and you can view the function variables and call stack. Viewing step through debugging
Use the VS Code debugger icons to step through the code. Using VS Code debugger icons to step through the code.
In the Local Invoke and Debug Configuration panel. Chose Save Debug Config.
Choose Add Local Invoke and Debug Configuration. Saving debug configuration
Enter a debug configuration name which creates a launch.json file and adds the debug configuration.
Naming debug configuration
You can create and save multiple debug configurations for different scenarios. See the AWS SAM documentation for more launch.json configuration options.
Using the Run and Debug panel
Deploying the application 1. Navigate to the Application Builder section and chose the Deploy SAM Application icon. Selecting Deploy SAM Application icon
AWS SAM provides two deployment options:
Viewing AWS SAM deployment options
Select Specify required parameters and save as defaults. Specifying SAM sync parameters
Select a Region to deploy the stack and enter a stack name. It is good practice to specify that this is a dev stack to avoid confusion when using the Deploy option. Entering dev stack name
Select an existing S3 bucket to store the artifacts, or create a new one. Selecting S3 bucket
Specify the Sync parameters. Ensure you select Watch as this automatically watches for code changes and quickly syncs code changes to the Lambda service Setting sync parameters
AWS SAM sync does an initial CloudFormation deploy to build the resources and then waits for code changes.
Make a change to the handler file code and save the file, Amending code
This performs a quick sync which reduces the time to test in the cloud. Quickly syncing code
You can use the Deploy option to deploy a non-quick sync test version, amending the stack name to differentiate it from the dev stack.
Naming test version stack
Remote invoke You can invoke the function in the cloud from your IDE. This allows you to test functionality without having to mock security, external services, or other environment variables.
Once the application is deployed, Application Builder detects changes to samconfig.toml and template.yaml, it updates the resources list with the cloud resources.
Viewing cloud resources
You can browse directly to the CloudFormation stack to view resources. Browsing to CloudFormation stack
Selecting the function provides quick link functionality, which includes function details and a link directly to the Lambda console for the function. Viewing function quick link options
Select Invoke in cloud.
Select the same local event file for the local invoke. Selecting local file for remote invoke
Choose Remote Invoke. The function invokes in the cloud using the local test event and displays the remote invoke results in the local IDE Output pane.
Viewing remote invoke results
Saving remote test event
Viewing logs You can fetch the Amazon CloudWatch Log streams generated by your Lambda function in the IDE.
Select the Search Logs icon. Selecting Search Logs icon
You can optionally filter the results.
Optionally filtering log results
Conclusion Lambda is introducing an enhanced local IDE experience to simplify the development of Lambda-based applications using the VS Code IDE and AWS Toolkit. This streamlines the code-test-deploy-debug cycle. A guided walkthrough helps set up your local development environment and provides sample applications to explore Lambda functionality. You can then build, debug, test, and deploy Lambda applications using icon shortcuts and the Command Pallette. This allows you to more easily iterate on your Lambda-based applications without switching between multiple interfaces.
For more serverless learning resources, visit Serverless Land.