Picture: AWS

AWS Toolkit for Visual Studio 2019

AWS (Amazon Web Services) offers an extra toolkit for Visual Studio 2017 and Visual Studio 2019 that integrates seamlessly to create projects based on AWS products.

The toolkit is available for VS2017 and VS2019 as well as for the older Visual Studio versions 2013 and 2015.

For the older versions, however, not all features will be offered, which is less due to AWS itself, but to the fact that simply VS2013 and VS2015 do not have the features at all (e.g. .NET Core).

You can download them directly here: https://aws.amazon.com/de/visualstudio/

Create your AWS project

After installing the toolkit, Visual Studio lists a number of templates to create your own project based on them. Just type "AWS" into the search bar to see the list of AWS projects.

2019-06-02_VS-AWS-Create-Project

As an example I have used a serverless template, which I now have to enter additional information such as the project name, solution name and directory.

This does not differ from the standard Visual Studio templates.

2019-06-02_VS-AWS-Configure-Project

AWS SDK - ASP.NET Core Serverless Blueprint

A special feature of the AWS Serverless Templates are now the so-called Blueprints.

At this point it is possible to use not only standard Lambda Functions or standard AWS Functions, but a special feature in the function world: ASP.NET Core as Serverless Function!

2019-06-02_VS-AWS-Project-App-Selection

Yeah, you read right.

The AWS SDK offers its own entry point, so an ASP.NET core application runs as a real Lambda function! Microsoft Azure or the Azure SDK cannot do this at the moment!

This fundamentally changes the billing of ASP.NET Core Applications. Previously, you had to use "simple" functions - both in the AWS and in the Azure world - if you only wanted to pay for per request.

With the AWS SDK it is now possible to pay for an entire application per call instead of with a reserved computing power. Especially for smaller, less frequented websites ASP.NET Core becomes more attractive again!

Visual Studio ASP.NET Core Serverless Project

After you create the ASP.NET Core Serverless Blueprint, the project looks like an ASP.NET Core project normally does.

2019-06-02-BenjaminAbt.Demos.AWSServerless

The special feature is the LambdaEntryPoint, which makes it possible to operate the application not only in a web server but also more efficiently in an AWS Lambda.

namespace BenjaminAbt.Demos.AWSServerless
{
    /// <summary>
    /// This class extends from APIGatewayProxyFunction which contains the method FunctionHandlerAsync which is the 
    /// actual Lambda function entry point. The Lambda handler field should be set to
    /// 
    /// BenjaminAbt.Demos.AWSServerless::BenjaminAbt.Demos.AWSServerless.LambdaEntryPoint::FunctionHandlerAsync
    /// </summary>
    public class LambdaEntryPoint :
        // When using an ELB's Application Load Balancer as the event source change 
        // the base class to Amazon.Lambda.AspNetCoreServer.ApplicationLoadBalancerFunction
        Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
    {
        /// <summary>
        /// The builder has configuration, logging and Amazon API Gateway already configured. The startup class
        /// needs to be configured in this method using the UseStartup<>() method.
        /// </summary>
        /// <param name="builder"></param>
        protected override void Init(IWebHostBuilder builder)
        {
            builder
                .UseStartup<Startup>();
        }
    }
}

If you now start the application locally (uses LocalEntryPoint.cs ), the standard browser opens as usual with a slim demo view.

2019-06-02_Chrome-BenjaminAbt.Demos.AWSServerless

Publish to AWS Lambda

In principle, it is not a good idea to publish an application directly from Visual Studio. A real application should always be built, tested and published through a real DevOps process!

Nevertheless, the AWS Toolkit also offers the possibility to publish an application directly from Visual Studio to AWS, which is perfectly fine for demos.

2019-06-02_VS-AWS-Publish-To-Lambda

If an AWS Publish Profile has already been set up (contains AWS Credentials), in principle only the name for the storage (project output files are stored here), the stack name (address endpoint name) and the region in which the application should run must be specified.

2019-06-02-Publish-AWS-Serverless-Application

Make sure that the application itself and also the storage must be in the same region, otherwise the deployment will crash. Unfortunately there is no warning in the Publish dialog.

If all information for the publication is given, publish can start. The AWS Visual Studio Toolkit provides a very detailed description of what happens during the release.

2019-06-02-Published-AWS-Lambda-Sample

Done! A few seconds later, the application can be accessed via the Internet on AWS Lambda.

2019-06-02_Chrome-BenjaminAbt.Demos.AWSServerless-Prod