Serverless Lambda Function AWS

Serverless Lambda Function AWS

09 July 2021

Before AWS Lambda function, let’s understand:

What is Serverless?

Serverless is a term that generally refers to serverless applications.

Serverless applications are ones that don’t need any server provision and do not require to manage servers.

AWS Lambda

AWS Lambda is an event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services.

It is a computing service that runs code in response to events and automatically manages the computing resources required by that code.

It was introduced in November 2014.

In AWS Lambda the code is executed based on the response of events in AWS services such as add/delete files in S3 bucket, HTTP request from Amazon API gateway, etc.

However, Amazon Lambda can only be used to execute background tasks.

AWS Lambda function helps you to focus on your core product and business logic instead of managing operating system (OS) access control, OS patching, right-sizing, provisioning, scaling, etc.

When building Serverless applications, AWS Lambda is one of the main candidates for running the application code.

Typically, to complete a Serverless stack you’ll need:

  1. Computing service
  2. Database service
  3. HTTP gateway service

Lambda fills the primary role of the compute service on AWS.

It also integrates with many other AWS services and, together with API Gateway, DynamoDB and RDS, forms the basis for Serverless solutions for those using AWS.

Lambda supports many of the most popular languages and runtimes, so it’s a good fit for a wide range of Serverless developers.

Characteristics of AWS Lambda

  1. Lambda functions will run your code only when called directly or when triggered by some outside event.
  2. It scales automatically which means it can handle from a few hundred requests to thousands of requests per second. You need not add or delete machines manually.
  3. You have to pay only for the time your code is running.
  4. It supports various runtimes – Node.Js, Java, Python, .NET, Go, Ruby, Rust.
  5. Lambda functions should not be a long-running process; it can run for a maximum of 15 minutes.

Launching your first Lambda Function

Step 1: Select Lambda Service

Sign-in into AWS console https://aws.amazon.com/console/ using your AWS credential.

If you are new to AWS you can create a new account. AWS provides 12 months of free tier access for selected services.

Step 2: Create Function

Click on build a function to create your first Lambda Function.

Step 3: Choose Options

On the next screen, you can choose whether you want to write your function from scratch, or to build a lambda function.

Step 5: Basic Info

On this screen, you have to provide basic information about your lambda function such as function name. You also need to set permission for your AWS Lambda function to access S3 buckets so you need to create an appropriate IAM role for the same.

In the execution role, you can choose whether you want to create a new role with basic permission or use an existing role, or create a role with some existing policy templates.

When you scroll down on the same screen, you are required to provide role information such as role name and to select policy template, which will contain all access permissions that will be provided to your lambda function.

Step 6: Trigger Info

  • In the next section on the same screen, you will be required to provide the trigger information, which means by what event your lambda function will be triggered.
  • In this scenario, we have to define the S3 bucket name, event type (such as PUT/POST/DELETE, etc.) of a new object and you can define the prefix and suffix.

Step 7: Lambda Function

  • In the next section on the same screen, you can see preconfigured lambda code provided by a selected blueprint.
  • This lambda function is written in python and is primarily reading the object from S3 bucket and then returning its content type to API.
  • You can further configure this lambda function according to your need.

Step 8: Final Screen

This will be the final screen for your lambda function where you can edit your lambda code, add new triggers, test your code by creating S3 events, set the environment variables, and can even change the runtime from python to any other language.

You can view logs in Cloudwatch by clicking on the Monitoring tab.

Conclusion

Lambda functions are undoubtedly innovative, low maintenance, low cost, scalable, and effective ways to create Dynamics CRM services without carrying the burden to host any servers.

Lambda functions are the future of serverless applications.

Request a quote