AWS Serverless: Develop, Test, and Deploy with AWS Lambda’s New Code Editor and SAM template
December 22, 2024

AWS Serverless: Develop, Test, and Deploy with AWS Lambda’s New Code Editor and SAM template

Did you know that in October 2024, AWS made a major update to the Lambda code editor in the console?

This new editor is built on the open source foundation of Visual Studio Code (VS Code). If you’re used to using VS Code as an integrated development environment (IDE) for development and debugging, you’ll find the updated Lambda code editor very familiar. It replicates the functionality and workflow of the desktop environment, bringing a seamless development experience to the AWS console.

In this article, I’ll walk you through the new Lambda code editor. We’ll explore key updates, including improvements to the code editor itself, enhanced test event configuration, and streamlined feature deployment and testing processes.

A standout feature of this editor is the ability to download AWS SAM (Serverless Application Model) or CloudFormation
Lambda function template. This feature lets you export a function’s code and infrastructure as code, allowing you to continue native development in your preferred IDE. After you enhance and test your function natively, you can redeploy it as a new or updated Lambda function. The AWS Lambda console then provides an intuitive interface for accessing, testing, and validating deployed functions.

Let’s take a look at the architecture/workflow diagram!

Lambda update console overview

The updated AWS Lambda host introduces several exciting features designed to enhance the developer experience. These include a VS Code-like interface, improved in-console functional code editing, and integrated support for Amazon Q’s generative AI to provide developers with intelligent assistance.

Below is an example of the updated editor interface.

lambda code

This is a very simple HelloWorld function code generated by Lambda. I have set up this function using AWS console.

Lambda test activity

Let’s configure a test event. This test event will be used by the function during execution.

Note that although this function doesn’t take any parameters, I’m still configuring the parameters. I also use this test event later when the function is updated to accept parameters.

Test events are created as data objects in JSON format. This is the JSON format data object expected by the lambda function during execution.

Lambda deployment and verification

After setting up the code and test events, it’s time to deploy the feature.

Once your function is successfully deployed, you can test it using the test events configured in the AWS console.

According to the function code, the expected result is the message: “Hello from Lambda!” as shown below.

Lambda – SAM/CloudFormation template

A noteworthy feature of the AWS Lambda console is the ability to view SAM/CloudFormation templates of functions you create. This template can serve as the basis for further enhancements in the native IDE. Once modified, you can seamlessly redeploy updated functionality, leveraging the power of infrastructure as code for iterative development.

Download the template as an AWS SAM file.

VS Code – Native development, testing and deployment!

Now that I have a SAM template, I can use it to enhance functionality in the native IDE. My local IDE setup includes VSCode and AWS SAM CLI.

I’ve created several workshops that demonstrate how to develop and validate Lambda functions locally. If these interest you, check out the other videos. The link is provided in the description and the video can be found in the playlist on my channel.

Since I’m using Python 3.13 (the latest version of the Python runtime), I have to install the latest AWS SAM CLI.

Update code enhancements

I’ll add the ability to extract the parameter “name” from the event and update the output message with the value in this parameter.

Let’s create the Lambda function code using the function code and the downloaded SAM template.

The SAM commands listed below can be used to build, verify, and deploy updated functionality.

  • sam build
  • sam local call -e
  • sam deploy -g

If you wish, you can now return to the AWS console and verify it. You’ll see the function in the AWS Lambda function manifest.

Cleanup – remove Lambda functions

After completing the setup, be sure to remove this feature to avoid unnecessary resource usage. If the function was built using the AWS console, it must be deleted from the console. Please pay attention to any messages that appear on the screen during the deletion process. Additionally, if you create new roles, logs, or other associated resources, remember to delete them manually.

in conclusion

In this article, I demonstrate how to effectively use the updated Lambda code editor to develop, test, and deploy Lambda functions.
Additionally, I show you how to download a SAM or CloudFormation template, continue development in the native VS Code IDE, validate the code locally, and deploy it to an AWS cloud region.

I hope you found this article helpful and informative!

Thank you for reading!

Watch the video here:


https://www.youtube.com/watch?v=sAnei-IzDOo

𝒢𝒾𝓇𝒾𝓈𝒽 ℬ𝒽𝒶𝓉𝒾𝒶
𝘈𝘞𝘚𝘊𝘦𝘳𝘵𝘪𝘧𝘪𝘦𝘥𝘚𝘰𝘭𝘶𝘵 𝘦𝘷𝘦𝘭𝘰𝘱𝘦𝘳𝘈𝘴𝘴𝘰𝘤 𝘪𝘢𝘵𝘦
𝘊𝘭𝘰𝘶𝘥𝘛𝘦𝘤𝘩𝘯𝘰𝘭𝘰𝘨𝘺𝘌𝘯𝘵𝘩

2024-12-22 01:42:18

Leave a Reply

Your email address will not be published. Required fields are marked *