The cloud computing market is huge with a massive scope of expansion. In a race of having the biggest market share, with many leading companies such as Azure, Google Cloud, providing cloud services, Amazon takes the lead.
Amazon Web Services (AWS), having established itself as an early leader, owns almost half the world’s cloud infrastructure market. Amazon reported revenues worth $15.4 Billion in 2018 and carried the dominance forward into 2019 with revenue of $16 billion (Q1 & Q2 combined).
In Q4 2019, the global cloud infrastructure market’s revenue amounted to $27 billion which brought the total revenue for the year to $96 billion. According to the reports of Synergy Research Group, Amazon’s market share, in 2019, amounted to 33% of the total worldwide public cloud infrastructure market.
AWS provides many different services which can be the components of a serverless application – AWS Lambda, API Gateway, S3, DynamoDB, SNS (Simple notification service), SQS (Simple queue service), AWS Step Functions, CloudWatch Events and Amazon Kinesis.
The focus amongst AWS serverless services is AWS Lambda, which is the compute layer of the serverless app development, where the code is executed. AWS development tools and services enable best practices while building and maintaining the serverless application with Lambda.
AWS Lambda: An overview
AWS Lambda is a high-scale, event-driven, provision-free serverless compute, that allows you to run code without any wastage of resources. It provides the cloud logic layer for the apps. AWS Lambda functions are triggered by different events that occur on AWS or any third-party services, which enables developers to build apps. When an event occurs, the code is executed and the required operations are carried out by the code. When there are multiple events occurring simultaneously, more copies of the functions are run parallelly by Lambda. Each request is scaled precisely which reduces the wasted capacity. Moreover, you pay only for the resources used or the compute time consumed.
Lambda can also be described as FaaS (Function as a Service), where the vendor provides provision-free scalability and built-in reliability and there are no virtual machines present. With Lambda, you can virtually run code for any type of app or backend service.
Each Lambda function that is created contains the code that needs to be executed, the configuration that defines the execution and event sources which detect and invoke the functions when they occur. For example, it runs code in response to HTTP requests with API Gateway, it runs code in response to the data changes with S3 bucket or DynamoDB table, it invokes code using API Calls made with AWS SDKs, and there are many more. Many event source options can trigger aws lambda function.
You can just upload the code and enter configuration – when and how to invoke – and Lambda will take care of everything else that’s required to run the code with high-availability.
Key feature of AWS Lambda
- Add Custom logic to AWS resources – AWS Lambda allows you to extend your services and add custom logic such as S3 Buckets and DynamoDB table. Which makes it easy to apply computation to data as it enters through the cloud.You create your function either by uploading your code or writing in the Lambda console, select or allocate the memory, timeout period and IAM (Identity and Access management) role.Then you have to trigger the function by specifying the AWS resource i.e. using S3 bucket, DynamoDB table or Kinesis stream. Lambda will function, launch and manage the compute as needed, when the resource changes. You can bundle Lambda functions with other deployment artifacts.
- Fault Tolerance and Automatic Scaling – With Lambda, the infrastructure automatically gets scaled without any additional configuration, depending on the number of requests. Sizing your deployment’s capacity is not necessary. Lambda serves incoming requests parallely by creating multiple instances as per requirement. Lambda has built-in tolerance and it maintains the compute capacity, across multiple Availability zones, ensuring robust service, which eliminates the data center downtimes or any other infrastructural failures.
- Fully Automated Administration – You do not have to update the underlying OS whenever patches are released or resizing / adding new servers as the usage grows because AWS Lambda manages everything – deploys the code, handles administration, maintenance, security patches, monitors via Amazon CloudWatch and also offers built-in logging. Lambda manages the infrastructure to run the code in availability zones – which allows you to completely focus on building back-end services. Using Lambda API or custom API via Amazon API Gateway, you can create differentiated back-end services for your apps which are triggered on-demand and process custom events instead of servicing these on the clients. With this, platform variation and battery drainage can be avoided.
- Build your own code and Run it globally – You can build a code using any third-party library or native library, without learning any additional languages or tools. With Lambda, package code (SDKs, libraries, frameworks, etc.) can also be used as a Lambda layer which can be managed and shared across platforms very easily. Lambda supports – Java, Node.js, Python, C#, Go, Power Shell and offers a Runtime API. This will allow you to author your functions using any additional programming languages. With Lambda@Edge, AWS Lambda can run your built code globally, across AWS locations, in response to Cloud Front events. These events can be requests for content, to or from origin servers and viewers. This lowers latency and more content personalization.
- Relational databases connection – Get access to fully managed connection pools for relational databases, using Amazon RDS Proxy. RDS Proxy scales and secures Lambda-based serverless apps which need to interact with relational databases. Reason being, it manages thousands of database connections to relational databases. Currently, it supports MySQL and Aurora. You can use RDS Proxy either through Lambda Console or RDS Console.
- Pay for what you use – With Lambda, you only pay for the resources you use i.e. the requests served and the compute time. You’re charged for execution duration and not by server unit. It’s cost effective, metered at increments of 100 milliseconds. Requests get scaled automatically, there is no wastage. Provisioned Concurrency –Payment is made for the amount of currency configured and duration or configuration. When you enable Provisioned Concurrency for your function, you also have to pay for requests and execution duration.
- Orchestrate Multiple functions – With AWS Step Functions, multiple Lambda functions can be coordinated. Step function allows you to define workflows which trigger a collection of Lambda functions, by using parallel, sequential, branching and error handling steps. You can build complex and stateful applications and back-end.
- Security – A built-in AWS SDK and integration is used by Lambda, with AWS Identity and Access Management (IAM) which ensures secure access to AWS services. Every code automatically runs within a VPC. You can use options to configure Lambda to “access resources behind VPC” which allows you to leverage custom security and network access control lists, to provide Lambda functions access to the resources within a VPC.
- Control over performance – With provisioned currency, you have more control over your serverless application’s performance. When you enable Provisioned Currency, it keeps functions initialized and hyper-ready to respond to double-digit milliseconds. It is ideal for any application, built using AWS Lambda, which needs greater control over function start time. Concurrency can be easily configured as needed and the level can be increased or decreased according to the high or low demand. Provisioned Concurrency efficiently achieves consistent performance for latency-sensitive applications and you do not have to manage compute resources. Moreover, Provisioned Currency does not require any changes to your code.
- Resource Model – You can choose the amount of memory allocation to the functions. The CPU Power, network bandwidth and disk I/O is allocated by AWS Lambda, proportionally.
When to use Lambda?
You need to adapt AWS Lambda if you do not want to maintain the servers, scaling and provisions but focus on the application code and business logic. AWS provides complete automated control for a good price. Given the fact that it allows you to write code in languages and runtime environments, it is perfectly suitable for compute platforms for many apps.
Lambda is the right choice for building APIs, along with API Gateway, with which you can reduce the time to market, optimize cost and obtain efficient results. AWS allows you to choose from different types of Lambda Functions and serverless design patterns, as per your requirements. There are other tasks which you can implement with Lambda such as creating cron job using CloudWatch and automating processes. You have the access to both memory and time, hence there are no restrictions for usage flows. You can smoothly go to full fledge micro services apps using AWS Lambda. With Lambda, you can create service-oriented actions which do not have to be running all the time. Therefore, Lambda functions are a good choice for distribution systems.
Building a Serverless application with AWS Lambda
An Application can be built by combining Lambda functions, event sources and other resources which are required to perform other tasks. Along with Lambda, the application architecture includes – Amazon API Gateway, DynamoDB, Amazon Cognito and Amplify Console.
While building a serverless application, you will need the following stack:
- Computing service
- Database service
- HTTP Gateway
Lambda provides the compute service and other services i.e. API Gateway, DynamoDB and RDS which form the basis of serverless solutions. Due to Lambda, individual tasks run for a short time and each task is self-contained.
All the components of the application can be collected in a single package, which can be deployed and managed as one source, using AWS CloudFormation. With CloudFormation, you can create a template defining your app’s resources and manage the app as a stack. AWS CloudFormation automatically goes back to the previous configuration if any of the updates fails.
To create an application with CI (Continuous Integration) pipeline, you can use Lambda Console, which provides starter projects for common app types and templates to create supporting resources. You need to create resources – Application, pipeline, repository, trigger, build project, deployment configuration, bucket and roles.
The resources and the application are defined in the CloudFormation templates which can be extended and customized. A template in the application repository can be modified and added to the DynamoDB, API Gateway and other resources.
AWS Lambda Function – Anatomy
Lambda function is stateless, meaning – it cannot store persistent information. For instance, if a variable is defined as a counter and a function is made to increase the counter’s value, by two, it would fail to work, each time it gets invoked. The reason behind this is the variable is defined and initialized within the confined code. It would get reinitialized again when the code is run the next time.
Though this statelessness has a purpose. It separates the data from the software. But Lambda is integrated with other Amazon services i.e. S3 Bucket, DynamoDB etc. which provide storage when needed.
The AWS Lambda Function has 3 important aspects –
- Trigger – A set of activities which run the provided code (functions). The activity could be a website, an API call, or an object going to the S3 Bucket. It can be anything.
- The Actual Function – The function constituted by a run-time code. At the time of writing the blog, AWS supports – Pythos, Node.js, C#, Java8 and Go.
- Resources – Every Function can be assigned to certain Roles. This allows the function certain privileges like S3 bucket contents can be read etc.
Events which can trigger a Lambda Function
The following events can be configured to trigger Lambda Function:
- Amazon DynamoDB – Table Updates
- S3 Buckets – Modifications to objects
- Amazon SNS – Sending Notifications
- Amazon Kinesis Stream – Messages arrival
- AWS CloudTrail – AWS API Call logs
- Amazon Cognito – Client Data Synchronization
Further, there can be custom events from mobile and web applications or other web services. There are two event models – a push event model, a pull event model. Lambda uses one of these models to work.
AWS Lambda Pricing
You Pay what you Use
AWS Lambda is a code which runs single invocation tasks. Which basically means that the code runs in an ephemeral container which gets terminated after serving its purpose. You pay what you use, based on the invocations. The configuration of each lambda function is based on memory size (GB) and the execution time is measured in milliseconds (ms)
AWS Charges $0.2/M<requests, each time a function is invoked. The overall duration is calculated from the time the code execution begins until it returns or terminates, which is rounded up to the nearest 100ms. The amount depends on how much memory you allocate of your function.
You can allocate any amount of memory to the function in 64 increments – between 128mb and 3008mb.
Current Price of AWS Lambda –
- Request Charges – $0.2/M requests
- Compute charges – $0.00001667/invocation
Free Tier – AWS offers a free usage tier which includes 1 Million invocations and 400,000 GB-seconds of compute time per month.
Practical Examples of AWS Lambda
- Media Transformation – With AWS Lambda, the issue of manual tasking during cross-device app development, can be solved. A multi-platform media and content delivery pipeline can be developed for automation. Suppose a request for an image is made but the image is unavailable in the S3, the request for image size redirects to API Gateway. This triggers the Lambda Function and the original image is fetched from S3, resized and uploaded. Lambda initiates each request of the unavailable image and each new request is not affected by the previous one.
- Deriving Multiple Data Format from a Single Source – There often occurs a requirement where a single object is needed in multiple formats. AWS Lambda, with S3 & SNS, helps in building a system which processes the data parallelly as the events occur.
AWS Lambda offers a variety of features and when combined with its pricing, it does make a great deal of service. It allows developers to create internal serverless systems which helps in handling incoming API requests from multiple sources such as mobile, IoT devices, internet powered systems and other third-party platforms. You can build secure and scalable applications with Lambda’s powerful toolkit. You can operate serverless websites, automatically run codes in response to various events without worrying about handling the infrastructure. There are a lot more advantages of using Lambda as a serverless platform.
AWS Lambda is an excellent choice for cloud computing products. However, if you’re thinking about your next application or any implementation, consider the features, price, workings and reviews. And migrate to Lambda based on what you have understood about AWS Lambda and how it can be used to improve the efficiency of your next solution.
What does aTeamIndia do?
aTeamIndia can help you migrate to Serverless, build Serverless applications, and train your team on the best practices in Serverless. We offer customized, scalable, robust and highly secure AWS (Amazon Web Services) development services to carve the future of your business.
With the right guidance and an experienced software developing partner, you can bring your envisioned ideas into existence and we are here to provide you just what you need to turn your idea into a refined product.
We look forward to serving your requirements. Contact our team today!