Source:digitalcloud.training

What is AWS Lambda? Lambda Function with Examples

If you like working with code but aren’t interested in devoting your life to maintaining the servers, infrastructure, and team required to support a traditional on-prem server-based computing environment, you’re going to love AWS Lambda.

What is AWS Lambda?

Source:stackify.com

It is a fully hosted and totally cloud-based serverless computing service launched in November 2014 by Amazon as a part of the Amazon Web Services that makes it easy to build, run, and deploy applications without the cost or hassle of having your own servers or infrastructure. It is a service that automatically runs code when an event occurs such as an HTTP request, reading data from an API, running a specific piece of code at a particular time, or processing results of an analysis and manages the computing resources that code requires.

The main difference between AWS Lambda and the traditional model of renting virtual machines, such as Amazon Elastic Compute Cloud (EC2) or Google Compute Engine, is that you don’t have to worry about provisioning capacity, configuring the OS and applications, patching or maintaining servers, or scaling. Lambda takes care of all of it for you.

This makes it a great option for developers who need to focus on building and delivering apps without having to worry about the underlying server infrastructure. For more information on AWS check this post.

The features of AWS Lambda

Event-driven computing

It enables you to define functions that are triggered by events. These events could be changes to data in an Amazon S3 bucket or sending email and SMS messages, calling APIs, and uploading files.

Automated administration

With AWS Lambda, you don’t need to manage any of your server infrastructure. It does all the administration stuff of the compute resources: from server and operating system maintenance, scaling, monitoring the code, to  provisioning compute capacity and logging.

Serverless architecture

It runs across AWS’s global infrastructure, handling everything from the back end to the front end and everything in between. You don’t have to manage the underlying infrastructure that hosts your code — it’s managed by AWS, which takes care of scaling and failure management for you.

Automatic scaling

You don’t need to worry about setting up any infrastructure or using a proxy or managing the request queues, Lambda scales automatically. You can easily handle hundreds or thousands of concurrent requests. All you need to do is just write the code and then let it run.

Pricing

Lambda uses an hourly computing model that depends on the amount of time your code is running. There are no upfront costs, no long-term commitment, and no setup fees. The cost varies depending on how much time your function is running and how many requests it receives, but it’s usually a couple of cents per hour per 1 million requests processed (the price drops based on request volume).

No need to learn a new programming language or framework to use AWS Lambda

Source:codingsight.com

Rather than learning something new and then spending days or weeks translating all your existing code, you can use the languages you already know.

It will work with any third-party library and any native programming language and also allow you to package up your code and any associated frameworks, SDKs, libraries, and more into “Lambda Layers” that can be shared among multiple functions.

Specifically,  Lambda supports the use of the following programming languages: Java, C#, Go, Python, PowerShell, Ruby, and Node.js. In addition, users can use the runtime API to write their code in a different language if they wish.

AWS Lambda concepts you should know

Function: This is the code that runs to execute a task in AWS Lambda after being invoked by an event.

Event: An “Event” activates a Lambda function.

Trigger: This is the configuration for invoking a AWS Lambda function.

Concurrency: This is the number of function requests being processed in a given time period.

Deployment package: A Lambda function is deployed using a deployment package. A .zip file and an Open Container Initiative (OCI) supported container image are the two types of deployment package used in AWS Lambda.

Execution environment: This is a dedicated and secure environment for running  AWS Lambda function.

Extension: Additional capabilities are added to a Lambda function via Lambda extensions.

Instruction set architecture: Lambda’s instruction set architecture determines the type of processor it uses. The two types are arm64 and x86_64. The first is a 64-bit ARM architecture (for AWS Graviton2 processor) and the second is a 64-bit x86 architecture (for x86-based processors).

Lambda Layer: a zipped (.zip format) archive file that can hold extra code or content.

Qualifier: A qualifier lets you specify a version or alias of an invoked function or a function you want to view.

How AWS Lambda Works

Source:cleveroad.com

With AWS Lambda, you are responsible only for your code – which is organized into functions.

So, using a Lambda API, Lambda functions can be invoked. Also, events generated by other AWS services can invoke Lambda functions. Following that, AWS Lambda runs the code on a computed resource and responds with the results. With these capabilities, you can use it easily in a variety of ways.

Some Application and Use Cases (With Examples)

  1. Image Processing:

It can be used for any type of image or video processing. You can use it to create different versions of an image, add a watermark, etc.

  1. Real-Time File Processing:

You can also use AWS Lambda to process files in real-time. For example, you can trigger a Lambda function when a file is uploaded to an Amazon S3 bucket.

  1. Dynamic Web Applications:

You can develop front-end applications that are hosted on Amazon S3, and dynamic back-end application logic that is processed by AWS Lambda and API Gateway. This can be done using the Serverless Application Model (SAM).

  1. Mobile Development:

It provides ready-to-use blueprints for mobile backends that can process events such as user sign-up and profile updates, push notifications, and sync data between devices and the cloud.

  1. Stream Processing:

You can build a serverless stream processing application using AWS Lambda and other AWS services like Amazon Kinesis.

  1. Data Processing

Real-time data processing using Kineses Streams, Dynamo DB streams, and S3 events. For example, you could build a Lambda function that processes a stream of log files from Amazon S3 and writes them to Amazon Elasticsearch Service for analysis.

  1. Chatbots

You can use AWS Lambda functions to build chatbots for popular chat apps such as Facebook Messenger, Slack, and Twilio.

  1. Internet of Things (IoT):

Using it, you can run code to connect devices to the cloud. It can be used to process real-time data from IoT sensors or devices; process IoT notifications received by Amazon SNS and send messages to connected devices using Amazon SQS.

  1. Image or video analysis

It can be used to run code in response to changes in images, stored videos, or streaming video from Amazon Kinesis Video Streams.

Some additional examples of AWS Lambda functions include:

  • Performing backups of your Amazon Elastic Block Store (Amazon EBS) volumes on a scheduled basis, so that you can quickly restore data if an Amazon EBS volume fails.
  • Automatically validating customer contact information when they submit support tickets by triggering an AWS Lambda function in response to Amazon Simple Notification Service (Amazon SNS) notifications.
  • Enforcing security requirements by blocking access to your applications deployed on Amazon Elastic Compute Cloud (Amazon EC2), in response to changes in AWS Identity and Access Management (IAM) user policies.
  • Automatically update Amazon DynamoDB tables from an Amazon S3 bucket whenever a new object is uploaded.

How To Get Started With AWS Lambda

Source:youtube.com

Step 1: Sign up for AWS.

If you don’t have an account, go ahead and create an AWS account.

Step 2: Create an AWS Identity and Access Management (IAM) user with administrator permissions.

You can follow this guide to create your IAM user.

Step 3: Get familiar with the Lambda console.

Step 4: Author and deploy Lambda functions.