Part 3 - Create .NET Core Serverless App

In this task you will create a ASP.NET Core Web API project that will run as a Lambda function. Inside the ASP.NET Core web API project you will create a jQuery calendar app which will use Cognito to authenticate users.

1. Open Visual Studio 2017, from the File menu select New > Project, under Visual C#, click AWS Lambda and then select “AWS Serverless Application (.NET Core)” project and enter the following name:

  • Name: CalendarWebApi

2. From Blueprints, choose the “ASP.NET Core Web API”, click Finish

Note: This will generate skeleton code for our project, and also a CloudFormation template that will deploy the solution. This blueprint relies on the Amazon.Lambda.AspNetCoreServer NuGet package to translate calls between API Gateway and the ASP.NET Core framework.

Note: The ASP.NET Core Web API blueprint project template creates two entry point classes, LocalEntryPoint.cs and LambdaEntryPoint.cs. The LocalEntryPoint class is used when running in your local dev environment, and leverages Kestrel, the ASP.NET Core webserver. This makes it really easy to test out your project locally before deploying it.The LambdaEntryPoint relies on API Gateway.

3. Add the Output window from the View menu by selecting > Output

4. From the Build menu select > Build Solution, and verify the build was successful in the Output window

5. Run the project by clicking IIS Express

6. Not to worry you should receive a “This localhost page can’t be found”

404 error message

7. Add “/api/values” to the end of the URL and you should receive the json array [“value1”,“value2”]

Info: the ValuesControllers Get method is called which returns the array

8. Back in Visual Studio stop the debugger by clicking on the red square symbol

9. The blueprint project we used creates an S3ProxyController, in the Soultion Explorer expand the Controllers folder and right click on the S3ProxyController file and click Delete as we will not be using S3 bucket for this project.

10. Now let’s remove the S3 references from the serverless.template file, double-click to open the serverless.template file in the Solution Explorer

  • “Parameters” Section: Remove the ShouldCreateBucket and BucketName parameters

Before:

After:

  • “Conditions” Section: Remove the CreateS3Bucket and BucketNameGenerated conditions

Before:

After:

  • Expand the “Resources > AspNetCoreFunction > Properties > Environment > Variables” Section: Remove the AppS3Bucket reference

Before:

After:

  • Expand the “Resources > Bucket” Section: Remove the Bucket Resource (Lines 38-44)

Before:

Note: There will be a parse error on line 38, to fix this error delete the comma at the end of line 12 (or at the end of the “AspNetCoreFunction” section)

After:

  • Fully expand the “Outputs” Section: Remove the S3ProxyBucket section

Note: Delete the comma at the end of line 43 to avoid encountering a parse error

Before:

After: