DEV Community

Cover image for A local Lambda development environment

A local Lambda development environment

Sharing some ways in which I streamline my workflow and speed up the feedback loop when developing for AWS Lambda

Two tools I use when developing for AWS serverless in general are LocalStack and the AWS Toolkit for VSCode which has recently been updated to include new features making it more compelling to use with Lambda.

The main way I speed up my feedback loop when developing in AWS Lambda is by using LocalStack. LocalStack is essentially an AWS environment running locally on your machine and I find it really useful for quickly testing many things not just Lambda functions.

It has a free tier which gives access to everything I’ve used in this article so go and sign up!

Setup LocalStack

Once signed up with LocalStack getting going is pretty simple.

LocalStack runs in a docker container and once you’ve followed the steps in the Getting Started guide you should be up and running. Once everything’s running the LocalStack console should look something like this:

Image of the localstack dashboard showing that the local cloud is running

To demonstrate a typical setup I use when developing I’m going to go through how I’d create a simple setup containing an SQS queue, a Lambda function and an S3 bucket. Messages on the SQS trigger the Lambda which writes the message that was received into the bucket.

Image of an AWS architecture containing an SQS queue, a Lambda function and an S3 bucket

Automate deployment to LocalStack

Generally I would be deploying code using CDK so, given that CDK is installed, I would initialise a new CDK project — in my case I would usually be using Typescript as the language:

cdk init --language typescript
Enter fullscreen mode Exit fullscreen mode

and then create the three components and necessary permissions in the CDK stack:

const bucket = new Bucket(this, "automated-bucket", {
  bucketName: "automated-bucket",
  versioned: true,
  removalPolicy: cdk.RemovalPolicy.DESTROY,
})

const sqs = new Queue(this, "automated-queue", {
  queueName: "automated-queue",
  visibilityTimeout: cdk.Duration.seconds(300),
  retentionPeriod: cdk.Duration.days(4),
  removalPolicy: cdk.RemovalPolicy.DESTROY,
})

const lambda = new NodejsFunction(this, "automated-lambda", {
  entry: "functions/test/src/index.ts",
  handler: "handler",
  runtime: cdk.aws_lambda.Runtime.NODEJS_22_X,
  environment: {
    BUCKET_NAME: bucket.bucketName,
  },
})

lambda.addEventSource(
  new SqsEventSource(sqs, {
    batchSize: 10,
  })
)

sqs.grantConsumeMessages(lambda)
Enter fullscreen mode Exit fullscreen mode

If I wanted to deploy this to an AWS environment I would use the following CDK commands:

cdk bootstrap
cdk deploy
Enter fullscreen mode Exit fullscreen mode

To deploy this to the LocalStack environment I install CDK Local which is a wrapper around CDK that executes the commands on LocalStack. So to bootstrap and deploy:

cdklocal bootstrap
cdklocal deploy
Enter fullscreen mode Exit fullscreen mode

Now everything is deployed to LocalStack which is great, however I’d rather not run a cdklocal command manually every time I’ve updated anything. To automate this deployment I use nodemon to watch for any changes in the stack and run the deploy command. To do that I use the following nodemon config file:

{
  "exec": "cdklocal deploy --require-approval never",
  "watch": [
    "lib",
    "functions"
  ],
  "ext": "ts"
}
Enter fullscreen mode Exit fullscreen mode

This configuration watches for changes in the lib directory which contains the CDK stack and the functions directory which contains the Lambda function and if any changes are made to ts files then runs cdklocal deploy --require-approval never . Approvals are turned off as I don’t want to have to approve and security related changes while I’m developing — I just want to save the file and it gets deployed. This is a local development environment so there shouldn’t be any problems 🤞

Now if I execute nodemon in the root of the project whenever I make any changes to either the stack or the Lambda function they will be deployed to LocalStack for me to test.

Image showing the results of a cdklocal deploy

This repository setup is here.

This is great and all changes get deployed ready for test however, as you can see from the screenshot, there is a delay of a few seconds especially when changing the Lambda. Given that that’s the component that would be changed most often when developing it would be good to get rid of the delay if possible…

Lambda hot reload in LocalStack

Well it is possible, using LocalStack’s Lambda hot reload 🔥

To use hot reloading create a Lambda to retrieve it’s code from an S3 bucket called hot-reload with a key of the path to the code on your local machine, LocalStack will then update the function every time there’s a change to files in the specified path.

Note — there’s no need to actually create the hot-reload bucket.

To use this I would usually add the Lambda into the CDK stack using hot reload:

   new Function(this, "hot-reloading-function", {
      runtime: cdk.aws_lambda.Runtime.NODEJS_22_X,
      functionName: "hot-reloading-function",
      handler: "index.handler",
      code: Code.fromBucket(
        Bucket.fromBucketName(this, "hot-reload", "hot-reload"),
        "path-to-repository/functions/test/dist"
      ),
    });ty
Enter fullscreen mode Exit fullscreen mode

Note the name of the bucket and the key in the call to Code.fromBucket .

Then remove the functions directory from the nodemon config so that it only deploys when the stack is changed:

{
  "exec": "cdklocal deploy --require-approval never",
  "watch": [
    "lib"
  ],
  "ext": "ts"
}
Enter fullscreen mode Exit fullscreen mode

Add another nodemon config into the Lambda directory that builds it whenever it’s changed:

{
  "exec": "npm run build",
  "ext": "ts"
}
Enter fullscreen mode Exit fullscreen mode

Then run nodemon into the Lambda directory as well as in the root of the project so that if the function code is changed the Lambda is hot reloaded while if the stack is changed then a full deploy happens.

This repository setup is here.

AWS Toolkit for VSCode

As a VSCode user I also often use the AWS Toolkit for VSCode for a number of things — especially the local Workflow Studio for editing Step Functions.

Recently (17th July 2025) AWS released an update that adds two new features that I would expect to become very useful when developing for Lambda:

  • Console to IDE integration which allows you to open a Lambda function in VSCode directly from the AWS console and then deploy any changes directly from the IDE.

  • Remote debugging which allows you to debug a Lambda function that is running in an AWS environment from within VSCode

Both features are pretty simple to use…

Console to IDE integration

There is now a new button on the Lambda console — Open in Visual Studio Code

Image showing button on the AWS console

which does exactly what it says and allows you to open and edit the function in the IDE and gives the option to deploy when changes have been made.

Image showing deployment options for Lambda function

This can also be initiated from within the IDE — find the function you want to edit in the Explorer and select the ‘Download…’ option, the function is then downloaded and can be edited and deployed.

Remote debugging

Once the Lambda is available in the IDE which can be done using either of the two techniques above it can be debugged remotely. To do this right-click on the Lambda in the explorer and select ‘Invoke Remotely’, or click the arrow button, the ‘Remote invoke configuration’ dialog is opened.

Image showing the remote invocation dialog

This dialog includes a checkbox for ‘Remote debugging’, tick that box, add a breakpoint into the function code, hit the ‘Remote invoke’ button and the Lambda will be invoked in the AWS environment but the breakpoint you’ve added will be hit in the IDE 🎉

Image showing a breakpoint being hit

Use AWS Toolkit with LocalStack

Wouldn’t it be cool if these two new Lambda features could be used within LocalStack?

Well, there’s good news 😃 and bad news 😦!

The good news is that the IDE integration seems to work, however I’ve not been able to get the remote debugging to work as yet (if I do I’ll update this post!)

It’s a little bit fiddly to setup as the toolkit doesn’t expose any configuration to use different endpoints so you need to edit the VSCode settings.json and add the following:

"aws.dev.endpoints": {
  "lambda": "http://localhost.localstack.cloud:4566"
}
Enter fullscreen mode Exit fullscreen mode

this tells the toolkit to use the LocalStack endpoint for Lambda meaning that the IDE integration can be used on LocalStack as well.

Top comments (0)