AWS Lambda Function with Layers

Lambda function with layer

AWS announced two new AWS Lambda features, Lambda Runtime API and Lambda Layers, on Nov 29, 2018. These features enables developers to build common code, manage it and share it between multiple functions.

A Layer is a zip archive which contains libraries and dependencies which can be imported to Lambda functions at runtime. They also support versioning which makes it possible to upgrade the Lambda layer with new code without impacting the Lambda functions using it. Lambda Layers provide two major benefits as below…

  1. If there are more than one Lambda function have same dependencies, those dependencies can be uploaded as a Layer and used across Lambda functions.
  2. The deployment package size of the Lambda package is reduced as the dependencies are no more required to be part of the deployment package.

Read More

AWS Lambda with SQS trigger using .NET Core-Part 3

Welcome back!!!

This is the third part of the article where we will learn about how to do increamental deployments to AWS Lambda functions.

During Part - 1 of this article we learned how to create Lambda project in .NET Core and how to use MsBuild to build, test and package the Lambda function.

During Part - 2 we are going to learn how to deploy the Lambda function to AWS and how the deployment can be automated and also test the Lambda function with SQS trigger from AWS Console.

Today in Part - 3 we are going to learn how to do use Terraform to deploy AWS Lambda function when we make change to code.

In the previous part we created Terraform script to create required resources on AWS and deploy Lambda Function. At the last of the Part-2 we ran following command to build, package and deploy the Lambda function.

1
dotnet msbuild ./Build/lambdawithsqs.proj /t:BuildPackageUploadDeploy

Now let’s make some change to the code of Function.cs. As part of this change we will modify ProcessMessageAsync method to write couple of more statements to the log. After this change the method looks like as following.

1
2
3
4
5
6
7
8
private async Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context)
{
context.Logger.LogLine("Entering method ProcessMessageAsync");
context.Logger.LogLine($"Processed message {message.Body}");
context.Logger.LogLine("Exiting method ProcessMessageAsync");

await Task.CompletedTask;
}

And run the MsBuild command again. The outcome of the command should have following two lines in it.

1
2
No changes. Infrastructure is up-to-date.
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Read More

AWS Lambda with SQS trigger using .NET Core-Part 2

Welcome back!!!

During Part - 1 of this article we learned how to create Lambda project in .NET Core and how to use MsBuild to build, test and package the Lambda function.

During Part-2 we are going to learn how to deploy the Lambda function to AWS and how the deployment can be automated and also test the Lambda function with SQS trigger from AWS Console.

So let’s begin. Lambda function can be deployed two ways.

  1. By manually uploading the package via AWS Console.
  2. By automating the deployment process.

There are various ways Lambda deployment can be automated and each of the way would require different set of tools and technologies.

The approach we will use here would use MsBuild, AWS CLI commands and Terraform. We already have used Msbuild and AWS CLI command in the first part of the article. Terraform is the new word here.

Following is the one-line introduction of Terraform.

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently.

More details about Terraform available at (Here).

For the lambda function deployment, Terraform needs to know from where to get the deployment package. Terraform can locate the deployment package from an S3 bucket. We will take that route. So before we can start the deployment using Terraform, we need to make sure that the specific bucket is created on S3 and also the package is available at the certain S3 bucket.

Read More

AWS Lambda with SQS trigger using .NET Core

In this article series I am going to show how to create an AWS Lambda Function using .NET Core and Amazon project template and also how to deploy the Lambda Function to AWS using Terraform.

This article series will be of 2 parts.

  • Part 1: Create, develop and build AWS Lambda Function using .NET Core
    • Create a new Lambda Function using .NET Core and Amazon project template
    • Build the project using MsBuild script
    • Create deployment package to be deployed on AWS
  • Part 2: Deploy Lambda function to AWS using Terraform
    • Create Terraform script to deploy Lambda Function on AWS
    • Automate Terraform script running via MsBuild
    • Preform incremental deployment of Lambda Function

Following tools will be used during the article, so make sure you have them install on your machine.

  1. Install .NET Core (Download)
  2. Install AWS Project templates for .NET (Instructions)
  3. Install AWS CLI (User Guide)
  4. Install Terraform (Download)
  5. Install Visual Studio Code (Optional) (Download)

You can use any platform (Windows, Mac, Linux). For this article, I am going to demonstrate everything on Mac.

Read More

Serverless API using AWS Lambda and CSharp

Develop and deploy Serverless API using AWS Lambada, Visual Studio and C#.

Serverless Applications

In today’s world of cloud computing where applications are becoming less and less dependent on physical platform or computer to run, serverless applications are becoming more and more popular because they are literally serverless. It means these applications are not more dependent on operating systems or hardware. Serverless applications are stateless and easily scalable enabling developer to focus on functionality and features of the application without worrying about resources and scalability.

Serverless applications are popular choice for the following scenarios

  • A service to be created to perform a very specific task upon request
  • A service to be created to perform a very specific task or job upon specific events
  • Data Processing or file processing tasks which does not require any interactions
  • Tasks which are trivial such as sending email

Read More