An often underused feature of the Serverless framework is the invoke local 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.
Serverless Framework Commands - AWS Lambda - Invoke Local_Emulate an invocation of your AWS Lambda function locally using the Serverless Framework_serverless.com
With VS Code, you have the ability to debug Node.js applications, including the option to launch an external program.
Debug Node.js Apps using VS Code_The Visual Studio Code editor includes Node.js debugging support. Set breakpoints, step-in, inspect variables and more._code.visualstudio.com
Put the two together and you have the ability to locally run and debug your Lambda functions.
In general, it’s a good idea to install Serverless framework as a dev dependency in a project because:
serverless.yml
file in the project
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
There, nice and easy :-)
Couple of things to note:
launch.json
config file in step 2AWS_PROFILE
) for the aws-sdk to access those resources in the correct AWS account
Hi, my name is Yan Cui. I’m an AWS Serverless Hero and the author of Production-Ready Serverless. 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.
You can contact me via Email, Twitter and 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 BEST PRACTICES 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.
You can also get 40% off the face price with the code ytcui.
Get your copy here.