Run AWS Serverless C# application locally in Visual Studio

When I created my first AWS Serverless application from a template (a blueprint) in Visual Studio, I expected that I could just run it locally the same way as I always run Azure Functions. However, I received the following error:

Unable to run your project. The “RunCommand” property is not defined.

An error message displayed when you attempt to start an AWS Serverless project created from a template in Visual Studio.
An error message displayed when you attempt to start an AWS Serverless application project created from a template in Visual Studio.

I cannot imagine working on a project without debugging it locally, so of course I started to dig how to start AWS Serverless application without deploying it to the cloud every time I want to test something.

Long story short, I learned that AWS Toolkit extension serves that purpose. Moreover, using any recent version, eliminates the need for manual setup. All you need to do to start a project is select the appropriate debug profile, “Mock Lambda Test Tool”, which surprisingly is not the default option.

A debugging profile that allows to start a Serverless project and debug it in Visual Studio.
A debugging profile that allows to start a Serverless project and debug it in Visual Studio.

This is trivial, but easy to miss if you expect that the default configuration works out-of-the-box. And I think that the next steps are more-or-less intuitive once you launch the test tool, and allow you to experiment until you stumble upon another issue 🙂

If, for whatever reason, such a debugging profile is not available in your Lambda project after creating it from a template, you can in theory add it manually following the instructions in the AWS Lambda Test Tool documentation. But this should not be needed if you have recent tooling.

As a side note: I cannot see any use for the non-working, default profile added by Visual Studio. So, I removed it from launchSettings.json to avoid confusion about this issue:

A default debug profile added when creating a project from a template. It seems useless and redundant. I decided to remove it.
A default debug profile added when creating a project from a template. It seems useless and redundant. I decided to remove it.

Happy coding and low cold start times to you!

Leave a Comment