How do you manage multiple AWS Lambda functions in Visual Studio?

You can create multiple lambda functions in one lambda project without using an API gateway or Serveless Project.

  1. Adding Serverless Template: Right click on your project and insert AWS server template. This template by default has a setup for AWS API gateway output. Modify this file to get rid of this. It should look like the following:

    {
        "AWSTemFormatVersion": "2010-09-09",
        "Transform": "AWS::Serverless-2016-10-31",
        "Description": "Test Project AWS Serverless Application.",
        "Parameters": {},
        "Resources": {
            "Register": {
                "Type": "AWS::Serverless::Function",
                "Properties": {
                    "Handler": "TestProject.Lambda::TestProject.Lambda.Function::RegisterAsync",
                    "Runtime": "dotnetcore2.1",
                    "CodeUri": "",
                    "Description": "Register Function",
                    "MemorySize": 256,
                    "Timeout": 30,
                    "Role": null,
                    "Policies": [
                        "AWSLambdaFullAccess"
                    ]
                }
            },
            "CreateUserFor": {
                "Type": "AWS::Serverless::Function",
                "Properties": {
                    "Handler": "TestProject.Lambda::TestProject.Lambda.Function::CreateUserForAsync",
                    "Runtime": "dotnetcore2.1",
                    "CodeUri": "",
                    "Description": "Create User Function",
                    "MemorySize": 256,
                    "Timeout": 30,
                    "Role": null,
                    "Policies": [
                        "AWSLambdaFullAccess"
                    ]
                }
            }
        }
    }
    

In this example we have two lambda functions defined Register and CreateUserFor.

  1. Now add a reference to this template in the projects aws-lambda-tools-defaults.json as follows:

     {
         "profile"     : "default",
         "region"      : "us-west-2",
         "configuration" : "Release",
         "framework"     : "netcoreapp2.1",
         "tem"      : "serverless.tem",
         "s3-bucket"     : "towmenot",
         "stack-name"    : "TowMeNot"
     }
    
  2. You can now define your function handlers with the names mentioned in the template. In this case:

     public async Task<bool> RegisterAsync(Registration registration, ILambdaContext context)
     {
         await RegisterHelper(registration);
         return true;
     }
    
     public async Task<User> CreateUserAsync(User newUser, ILambdaContext context)
     {
         return await CreateUserHelper(newUser);
     }
    

If you use the AWS Lambda Project(.Net Core) template, you can only write one function per project. You can see that the aws-lambda-tools-defaults.json file only contains configuration for one function.

However, if you use AWS Serverless Application(.Net Core) template, you can manage multiple Lambda functions in one project to response to different API call using API Gateway. This is achieved through CloudFormation.

Check out this AWS ReInvent video: https://www.youtube.com/watch?v=Ymn6WGCSjE4&t=24s Jump to 31:08 to see how AWS Serverless Application with multiple Lambda functions works.