Aws Lambda On Visual Studio For Mac

March 22, 2017

  1. Visual Studio
  2. Visual Studio Community For Mac

'The easiest way to get started is with the AWS Toolkit for Visual Studio which includes project templates for individual C# Lambda functions, full C# serverless applications, and tools to publish both project types to AWS,' it said. As my first medium post, I wanted to list the steps I used to enable the ability to run AWS Python lambda functions locally on my Mac running High Sierra using VS Code as my IDE. Disclaimer: There.

This blog post will provide you with a brief introduction to using C# and .NET Core with AWS Lambda and also look at the different programming models available when using .NET Core with Lambda.

Serverless and AWS Lambda

AWS Lambda is the serverless product offered by Amazon Web Services. Serverless does not mean that there is no server involved - obviously there is - but just that managing servers, scaling, etc is not something that you need to worry about.

What you need to worry about (as programmer) is writing the code that executes the logic. You can then deploy it to a serverless environment such as AWS Lambda and it will take care of scaling etc. Some of the other offerings available are Azure Functions, Google Cloud Functions and also Webtask.

The other advantage is that serverless environments only charge you for the time your code takes to execute. So if you have a small POC you want to develop, this is ideal as you do not have to worry about paying for a server which sits idle 99% of the time.

Programming models for C# / .NET Core

I have only started playing around with AWS Lambda recently, but from what I can see so far there are basically 3 models which you can use when developing AWS Lambda functions using .NET Core and C#.

Visual Studio

  • Plain Lambda Function. In this case you create a Lambda function which is a simple C# class with a function. This function can be triggered by certain events, or triggered manually from an application.
  • Serverless Application. In this case you can deploy an AWS Lambda function (or collection of functions) using AWS CloudFormation and front it with AWS API Gateway.

    You can also read more about this model in Deploying Lambda-based Applications.

  • ASP.NET Core app as Serverless Application. This is a variant of the model above, but in this instance your entire exiting ASP.NET Core application is published as a single Lambda function. This then utilizes the API Gateway Proxy Integration to forward all request coming through API Gateway to this Lambda Function.

    The Lambda function then hands the request off to the ASP.NET Core pipeline. So you have all the middleware you love at your disposal.

    This means that you basically have the normal ASP.NET Core request pipeline, but instead of IIS/Nginx and Kestrel, you have API Gateway and Lambda. So instead of this:

    You have this:

In the coming blog posts I will dive deeper into each of these.

So why AWS Lambda and not any of the others?

So I guess another question is why I am using AWS Lambda and not the offerings from Microsoft, Google or Auth0’s own WebTask? Well, for a couple of reasons which are true at the time of writing this blog post:

  1. It supports .NET Core - the others don’t. Google Functions isn’t even generally available yet.
  2. The 3rd programming model I mentioned above (ASP.NET Core app as Serverless Application) is one which interests me the most. I can take an entire ASP.NET Core app and publish it to Lambda. This means I can test my app locally with my normal development flow, and then simply push it to AWS to host it as a Lambda function.

Some resources to get you started

  • Serverless Development with C# and AWS Lambda (video from re:Invent 2016).

    I recommend watching this video first as it gives a great overview of AWS Lambda, the C# and Visual Studio support for AWS Lambda as well as the 3 programming models I discussed above.

Also stay tuned, as I plan to do more posts on C#, .NET Core and Lambda in the future.

The GA version of AWS Toolkit for Visual Studio 2017 has been released to the Visual Studio Marketplace

Original Post

Today we released a preview of our AWS Toolkit for Visual Studio that includes support for the release candidate (RC) version of Visual Studio 2017. Because this Visual Studio release contains some significant changes for extension developers, we're making this preview available in advance of the formal release. We highly encourage you to pass along feedback about any issues you find or whether you were successful using the preview by commenting on this GitHub issue.

Visual

AWS Lambda .NET Core Support

Visual Studio 2017 also contains support for the new MSBuild project system for .NET Core projects. With this preview of the toolkit, we've updated the .NET Core Lambda support to use the new build system. For existing Lambda projects based on the Visual Studio 2015 project.json-based build system, Visual Studio 2017 offers to migrate them to the new build system when you open the projects.

Downloading and Installing the Preview

The AWS Toolkit for Visual Studio contains MSBuild target files for AWS CloudFormation projects. In previous releases of Visual Studio, you had to install these files and dependencies for an extension outside of the Visual Studio folder hierarchy. This required us to use a Windows Installer to install the toolkit. Starting with Visual Studio 2017, these MSBuild extensions exist within the Visual Studio folder hierarchy and can be installed from the VSIX extension package without an installer. As the installer technology we use doesn't yet support Visual Studio 2017, we've decided to distribute the preview as a VSIX file only.

To install the preview

  • Download the VSIX file from the preview link
  • Double-click the VSIX file. This launches the VSIX Installer process, as shown.

Visual Studio Community For Mac

After the installer finishes, the toolkit functions as it has in previous versions of Visual Studio.