One of the complaints developers often have for AWS Lambda is the inability to run and debug functions locally. For Node.js at least, the Serverless framework and VS Code provides a good solution for doing just that. An often underused feature of the Serverless framework is the command, which runs your code locally by emulating the AWS Lambda environment. Granted, it’s not a perfect simulation and only works with Node.js and Python, but it has been good enough for most of local development needs. invoke local _Emulate an invocation of your AWS Lambda function locally using the Serverless Framework_serverless.com Serverless Framework Commands - AWS Lambda - Invoke Local With VS Code, you have the ability to applications, including the option to launch an external program. debug Node.js _The Visual Studio Code editor includes Node.js debugging support. Set breakpoints, step-in, inspect variables and more._code.visualstudio.com Debug Node.js Apps using VS Code Put the two together and you have the ability to locally run and debug your Lambda functions. Step 1 : install Serverless framework as dev dependency In general, it’s a good idea to install framework as a dev dependency in a project because: Serverless it allows other developers (and the CI server) to use the Serverless framework for deployment without having to install it themselves it prevents incompatibility issues when you have an incompatible version of Serverless framework installed to that used by the file in the project serverless.yml since Serverless v1.16.0 from the deployment package so it wouldn’t add to your deployment size dev dependencies are excluded Step 2 : add debug configuration Invoke the “sls invoke local” CLI command against the “hello” function with an empty object {} as input. It’s also possible to invoke the function with a JSON file, see doc: http://bit.ly/2w1HrQh Step 3 : enjoy! There, nice and easy :-) Couple of things to note: if your function depends on environment variables, then you can set those up in the config file in step 2 launch.json if your function needs to access other AWS resources, then you also need to setup the relevant environment variables (eg. ) for the aws-sdk to access those resources in the correct AWS account AWS_PROFILE this approach will not work for recursive functions (well, the recursion will happen on the deployed Lambda function, so you won’t be able to debug it) Hi, my name is . I’m an and the author of . I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless. Yan Cui AWS Serverless Hero Production-Ready Serverless You can contact me via , and . Email Twitter LinkedIn Check out my new course, . Complete Guide to AWS Step Functions In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, design patterns and best practices. Get your copy . here Come learn about operational for AWS Lambda: CI/CD, testing & debugging functions locally, logging, monitoring, distributed tracing, canary deployments, config management, authentication & authorization, VPC, security, error handling, and more. BEST PRACTICES You can also get off the face price with the code . 40% ytcui Get your copy . here