Skip to content

Create Serverless Application using AWS Lambda

Purpose & Background

The purpose of this lab is to demonstrate how you create serverless application using AWS Toolkit project template in Visual Studio and publish it to AWS Lambda. You will need to have a working AWS account to use this lab.

Lab Exercises

The following exercises should be completed in order for this lab:

  1. Create an AWS Serverless application
  2. Publish the application to AWS Lambda
  3. Test the application within Visual Studio
  4. Check and verify your AWS serverless application in the Console

Prerequisites

The following are the prerequisites required in order to complete the lab:

  1. Microsoft Visual Studio 2017 or above installed on your computer
  2. AWS Toolkit for Visual Studio 2017
  3. AWS Account and IAM user with security key id and secret code Internet connection

Part 1 – Create an AWS Serverless application

In this part you are going to create the AWS serverless application using project template from the AWS Toolkit for Visual Studio.

  1. Go to File -> New -> Projects and select AWS Lambda in the left side and select “AWS Serverless Application (.NET Core)” Picture 1
  2. In the Select Blueprint windows, make sure to select “Simple S3 Function” and click “Finish” Picture 2
  3. Visual Studio will create the project and you will have C# source file, CloudFormation template, and JSON configuration file Picture 3
  4. Edit the function, add a string “Please provide S3 event” as shown here Picture 4
  5. Build the project to make sure it has no errors so you can publish to AWS Lambda.

Part 2 – Publish the application to AWS Lambda

  1. Right click on the project name and select “Publish to AWS Lambda” Picture 5
  2. Make sure to select the region that you want to use, and enter the name of the Stack (CloudFormation stack), then click “Next” Picture 6
  3. Enter the name of the new S3 bucket that you want to use with this AWS Lambda function, then click “Publish” Picture 7
  4. The AWS Toolkit will start publishing the serverless application, Picture 8
  5. After that, it will start creating the stack, and you will be able to see the progress as shown here Picture 9
  6. Wait for couple of minutes and you will see that the process is complete, Picture 10
  7. If you refresh the “AWS Explorer”, you will be able to see the new AWS Lambda function that you just created and published there under the “AWS Lambda” node. Picture 11

Part 3 – Test the application within Visual Studio

  1. Double click on the function name, this will open the window where you can run and test your AWS Lambda function
  2. Click on the “Invoke” button Picture 12

Part 4 – Check and verify your AWS serverless application in the Console 1. Go to AWS Console https://aws.amazon.com and sign in 2. Go to Lambda section under “Compute” section 3. You will see the AWS Lambda that you just created Picture 13