Friday, 1 November 2019

Publish Lambda from Visual Studio



Here are the steps to publish .Net project as lambda in AWS from visual studio.

Step 1: Edit .csproj file and add below line of code.

<PropertyGroup>
    <AWSProjectType>Lambda</AWSProjectType>
  </PropertyGroup>

Step 2: Add Lambda function handler that will be init for API Gateway request.

public class LambdaFunction : APIGatewayProxyFunction
    {
        protected override void Init(IWebHostBuilder builder)
        {
            builder.UseContentRoot(Directory.GetCurrentDirectory())
                   .UseStartup<Startup>()
                   .UseLambdaServer();
        }
    }

Step 3: Add aws-lambda-tools-defaults.json file that will be used to store the publish settings.


Step 4: Finally, Publish Lambda to AWS from Visual Studio, by right click project and “Publish to AWS Lambda”. A wizard will open as shown below.




Settings to be configured in the above wizard

· Define environment variables (Staging or Production). Based on this variable, appsettings file will be executed.
·   Give PWA_Lambda_access IAM role to lambda function.
·   For .Net application Minimum RAM size is required 256MB.
·   All the lambda must be in VPC with proper security group to communicate with other assets.
·   Lambda stays warm for 15mins which are deployed in VPC. The idle lambda will be disposed after 15 mins and new request will be served from cold start.

With this Lambdas will be published on AWS.


No comments:

Post a Comment