Demystify the DX for Lambda functions

Rate this content
Bookmark

In this session, I share with you how AWS CDK and AWS Toolkit can simplify the developer experience to run serverless workloads in the cloud

A session with no slides, just an IDE and a CLI for deploying an API in the cloud, update it quickly, and retrieve logs without leaving your favourite IDE!

This talk has been presented at DevOps.js Conf 2024, check out the latest edition of this JavaScript Conference.

FAQ

You can use AWS Cloud Development Kit (CDK) along with your favorite IDEs like Visual Studio Code or IntelliJ to develop a serverless workload using Lambda functions.

AWS Cloud Development Kit (CDK) is an infrastructure as code tool offered by AWS that allows you to write code in your favorite language. It generates a CloudFormation template for the deployment and provisioning of your code and infrastructure.

You can test your Lambda functions locally using AWS SAM (Serverless Application Model). You can use the command 'SAM local start API' to start a local API for testing.

Using ESBuild with AWS CDK helps to make your bundle size smaller. It allows bundling with configurations that support ESM modules and top-level await.

The 'cdk deploy' command deploys your AWS CDK application to an AWS account. It checks your infrastructure and code changes and updates the deployment accordingly.

You can speed up the deployment process using the 'cdk deploy --watch' command along with the 'hotswap' flag. This allows you to swap your code underneath the Lambda function without passing through CloudFormation, making the feedback loop faster.

AWS Lambda Power Tools is an open-source tool that helps operationalize the observability of your applications by adding tracing, metrics, and logs.

You can visualize your AWS CDK infrastructure using AWS Application Composer. It generates a visual representation of your deployed infrastructure from the CloudFormation template.

Amazon CodeWhisperer is a tool integrated with AWS Toolkit that uses generative AI to assist in creating code based on comments you provide.

Amazon Q is a tool that allows developers to ask questions about their code and receive suggestions for improvements. It can provide explanations, optimizations, and code snippets to enhance code performance.

Luca Mezzalira
Luca Mezzalira
30 min
15 Feb, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Welcome to this session on Lambda Developer Experience. Learn about using AWS Cloud Development Kit (CDK) to write code in your favorite language and automatically generate CloudFormation templates. Test locally with the SAM CLI and deploy with CDK. Accelerate testing and updates with CDK flags. Use the AWS Toolkit to invoke Lambda functions, analyze logs, and generate code with Application Composer.

1. Introduction to Lambda Developer Experience

Short description:

Welcome to this session about Lambda Developer Experience. Discover tools to properly develop serverless workloads using Lambda function directly with Visual Studio Code or IntelliJ.

Hi, and welcome to this session about Lambda Developer Experience. How often you have found yourself that you are deploying your Node.js workload on the cloud and you need to wait for CloudFormation or Terraform or whatever else that has to deploy all your code every single time, despite you change maybe one line of code, the feedback loop that you have in order to wait for the deployment is pretty long. Sometimes you go out for a coffee, maybe you lose the momentum, and therefore, today I want to show you what are the tools that are available for you to develop properly a serverless workload using Lambda function, your favorite compute service directly with Visual Studio Code or IntelliJ because all the things that I'm going to show you today are going to be valid for VS Code as well as IntelliJ.

2. Using AWS Cloud Development Kit (CDK)

Short description:

AWS Cloud Development Kit (CDK) is an infrastructure as code tool provided by AWS. It allows you to write code in your favorite language and automatically generates a CloudFormation template for deployment. Let's look at an example: a simple Hello World application using ESM with nodes and CDK. CDK lets you write TypeScript and extends the Lambda function with additional capabilities like bundling options using ESBuild. Deploying the solution is as simple as running 'cdk deploy' and choosing the profile with the necessary information. CDK will handle the deployment, including the creation of an HTTP API acting as a proxy through API Gateway. Once deployed, you can access the API using the provided URL.

So let's start. First of all, what we are going to use today is AWS Cloud Development Kit, CDK as everyone refers to, is one of the infrastructure as code tools that are offered by AWS and allows you to write with your favorite language and then automatically behind the scene when we are building our artifact, what happens is that we are generating a CloudFormation template that will be then used for the deployment and provisioning of your code and infrastructure.

Now, let's try to see an example. I prepared a couple of examples so we can start to look into that. So the first example here is about a very simple Hello World example. I created this template for using ESM with nodes and using CDK for defining my infrastructure. So as you can see here, the beauty of CDK is I'm writing TypeScript that is in this case my favorite language for writing CDK. And here I have a high-level construct like node.js function that is extending the Lambda function. So as you can see here, it's extending this construct, this low-level construct that is called Lambda.function and it's adding new capabilities like the possibility to add bundling options. By default, CDK offers you the possibility to use ESBuild and therefore why not leverage that for making our bundle size smaller. So as you can see here, I use the bundling with a bunch of configuration that allows me to have the possibility to use ESM modules as well as other capabilities like top-level await for instance.

And now if we want to deploy this solution in an AWS account, it is as simple as writing here cdk deploy and then I decide which profile that I configure multiple profile in my machine I want to use where I have the region, I have my information needed in order to deploy this workload on the cloud. Now it's the first time that I'm doing that. So as you can see, CDK is telling me, oh by the way, there are a few things that you need to deploy, that are all the things in green. As you can see here, that will be needed in order to have this API up and running inside my system. So okay, so this one is as simple as a lambda function with an HTTP API that acts as a proxy that shows as API gateway the possibility to expose your API. So in one minute, this will be up and running and available on the cloud. And in the meantime, we can see that here we have the definition of my hello ESM lambda. Then we have an HTTP API definition that you can easily do with CDK. I just create the integration that basically is allowing you to have all the roles and settings needed in order to wire on a specific route your lambda function. And here you have the path that is the root path, the method that you can invoke this specific lambda function. And that's basically what you get. And at the end, we are going to have also this construct, this CFN output, basically it highlights inside your command line, the URL where you can find this API. As simple as that. So now we have deployed everything. As you can see, we have a URL that is useful. So if everything goes well, we should have our API up and running. And here we are. We have hello node ESM module. That is exactly what we have here, as you can see.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

AWS Lambda under the hood
Node Congress 2023Node Congress 2023
22 min
AWS Lambda under the hood
Top Content
In this Talk, key characteristics of AWS Lambda functions are covered, including service architecture, composition, and optimization of Node.js code. The two operational models of Lambda, asynchronous and synchronous invocation, are explained, highlighting the scalability and availability of the service. The features of Lambda functions, such as retries and event source mapping, are discussed, along with the micro VM lifecycle and the three stages of a Lambda function. Code optimization techniques, including reducing bundle size and using caching options, are explained, and tools like webpack and Lambda Power Tuning are recommended for optimization. Overall, Lambda is a powerful service for handling scalability and traffic spikes while enabling developers to focus on business logic.
AWS Lambda Performance Tuning
Node Congress 2024Node Congress 2024
25 min
AWS Lambda Performance Tuning
This Talk covers various optimization techniques for Lambda functions, including parameter fetching, code minification and bundling, observability with Power Tools and X-Ray, baseline testing with load testing tools, caching with Elastic Cache and Redis, and optimizing code size and memory usage. The importance of library choices, power tuning for cost and performance, leveraging subprocesses and sandboxes, and adjusting concurrency limits are also discussed. Overall, these techniques can significantly improve Lambda function performance.
Building Real-time Serverless GraphQL APIs on AWS with TypeScript and CDK
React Summit 2020React Summit 2020
25 min
Building Real-time Serverless GraphQL APIs on AWS with TypeScript and CDK
This Talk provides an introduction to JavaScript and React, as well as insights into building real-time serverless GraphQL APIs with TypeScript, AppSync, and CDK. It covers the concepts of GraphQL schema, data sources, and resolvers, as well as the use of GraphQL subscriptions for real-time communication. The Talk also highlights the features of AppSync and CDK for building APIs and infrastructure. It concludes with a demonstration of creating an API with CDK and AppSync, including the creation of Lambda functions and DynamoDB tables.
Automate React Site Deployments from GitHub to S3 & CloudFront
DevOps.js Conf 2021DevOps.js Conf 2021
33 min
Automate React Site Deployments from GitHub to S3 & CloudFront
This Talk focuses on automating React deployments to S3 and CloudFront using a CICD pipeline in AWS. It covers setting up the pipeline, sourcing code from GitHub, and configuring infrastructure with Terraform and Terragrunt. The Talk also demonstrates the process of building and deploying a React application using AWS CodeBuild and CodePipeline. Overall, it provides a comprehensive overview of the tools and techniques involved in automating React deployments in AWS.
Infrastructure as Code for React Application on AWS Written in TypeScript
React Advanced Conference 2021React Advanced Conference 2021
30 min
Infrastructure as Code for React Application on AWS Written in TypeScript
This Talk covers infrastructure as code using Terraform and CDK. The speaker demonstrates how to build infrastructure for a React application, including an S3 bucket and connecting to a real domain. They also discuss configuring cache behavior, CloudFront, and remote backends. TypeScript is highlighted as a powerful language for infrastructure as code, and the importance of automation and well-documented code for global-scale infrastructures is emphasized.
Building a sophisticated CodePipeline with CDK in a Monorepo Setup
DevOps.js Conf 2024DevOps.js Conf 2024
8 min
Building a sophisticated CodePipeline with CDK in a Monorepo Setup
Imagine starting as an AWS DevOps engineer in a small company. Your boss wants an all-in AWS approach, with CICD entirely on AWS for automated deployments. Use AWS CDK for creating a pipeline, stages, and actions. Learn how to handle multiple pipelines for different accounts and handle manual approval for staging and production environments. Discover how to trigger pipelines with EventBridge and Lambda, and create sophisticated pipelines for different scenarios.

Workshops on related topic

Building Serverless Applications on AWS with TypeScript
Node Congress 2021Node Congress 2021
245 min
Building Serverless Applications on AWS with TypeScript
Workshop
Slobodan Stojanović
Slobodan Stojanović
This workshop teaches you the basics of serverless application development with TypeScript. We'll start with a simple Lambda function, set up the project and the infrastructure-as-a-code (AWS CDK), and learn how to organize, test, and debug a more complex serverless application.
Table of contents:        - How to set up a serverless project with TypeScript and CDK        - How to write a testable Lambda function with hexagonal architecture        - How to connect a function to a DynamoDB table        - How to create a serverless API        - How to debug and test a serverless function        - How to organize and grow a serverless application


Materials referred to in the workshop:
https://excalidraw.com/#room=57b84e0df9bdb7ea5675,HYgVepLIpfxrK4EQNclQ9w
DynamoDB blog Alex DeBrie: https://www.dynamodbguide.com/
Excellent book for the DynamoDB: https://www.dynamodbbook.com/
https://slobodan.me/workshops/nodecongress/prerequisites.html
Frontend to the Cloud Made Easy - A ReactJS + AWS Workshop
DevOps.js Conf 2024DevOps.js Conf 2024
59 min
Frontend to the Cloud Made Easy - A ReactJS + AWS Workshop
Workshop
Eyal Keren
Eyal Keren
This workshop enables you to learn how to develop React applications, and then deploy them to the cloud (or building them to the console) coupled with a backend, fully abstracted, with no complex backend configuration, simplifying the building and deployment of frontend & web apps to the cloud.