AWS Lambda


Card image cap

AWA Lambda

Credit: Image Source


AWS Lambda is a serverless service that allows you to deploy your service, and you do not need to worry about infra. AWS take care infra itself according to requirements. It is a function triggered by an event; the event can be a new file in s3 buckets, a message in the kinesis stream, or an SQS queue.


Advantages:

1. Serverless: You need not manage servers. Lambda runs your code on highly available, fault-tolerant infrastructure spread across multiple Availability Zones (AZs) in a single Region, seamlessly deploying code, and providing all the administration, maintenance, and patches of the infrastructure 2. Scaling: It automatically scales your applications in response to incoming traffic. 3. Flexibility: Lambda can be used with other AWS services, such as S3, DynamoDB, and SNS, to build various applications and backends. 4. Cost-effective: You will pay according to the usage of the service. you are charged for every millisecond (ms) your code runs, and the number of times your code is run. You pay for consistent throughput or run duration, instead of by server unit.

Its Limitations

1. Cold starts and latency: When the Lambda service receives a request to run a function via the Lambda API, the service first prepares an execution environment. During this step, the service downloads the code for the function, which is stored in an internal S3 bucket (or in Amazon ECR if the function uses container packaging). It then creates an environment with the memory, runtime, and configuration specified. Once complete, Lambda runs any initialization code outside of the event handler before finally running the handler code. 2. Vendor Specific: Its tight integration with services like IAM, Amazon S3, API Gateway, or Amazon EC2 means switching to a different provider may be impossible. 3. Fixed-concurrency: The default set limit of a number of the lambda functions that can be executed parallel is 1000. You can adjust it according to your use cases. 4. Timeout: Lambda is terminated after 15 minutes. It is not feasible for long-running jobs 5. Monitoring and observability: In production, observability can be a challenge because you can’t log in to a server; you have to prod and poke the code from the outside to debug issues seen at runtime. The default option of Amazon Cloudwatch Logs can feel clunky and difficult to navigate. 6. permissions and networking issues can be difficult to debug because you can’t access the server with a terminal in the traditional way to quickly figure out the problem. 7. Stateless: It does not maintain the state of the previous call for future requests. If your service is required to maintain the database connection for future requests, then it will not be a good choice 8. Langauge constraints: You need to write code in the languages that AWS Lambda supports

Overall, AWS Lambda will be a good choice if you do not want to worry about infra and your service follows the below criteria 1. If a few milliseconds to a few seconds delay will not cause any issue 2. It is execution is completed within the time limit of Lambda timeout 3. Traffic burst is not more than the set limit concurrency of lambda 4. The language you want to write code is supported by Lambda 5. The current lambda API call does not depend on the results of previous requests.

When to use Lambda

Lambda is an ideal compute service for application scenarios that need to scale up rapidly and scale down to zero when not in demand. For example, you can use Lambda for: File processing: Use Amazon Simple Storage Service (Amazon S3) to trigger Lambda data processing in real time after an upload. Stream processing: Use Lambda and Amazon Kinesis to process real-time streaming data for application activity tracking, transaction order processing, clickstream analysis, data cleansing, log filtering, indexing, social media analysis, Internet of Things (IoT) device data telemetry, and metering. Web applications: Combine Lambda with other AWS services to build powerful web applications that automatically scale up and down and run in a highly available configuration across multiple data centers. IoT backends: Build serverless backends using Lambda to handle web, mobile, IoT, and third-party API requests. Mobile backends: Build backends using Lambda and Amazon API Gateway to authenticate and process API requests. Use AWS Amplify to easily integrate with your iOS, Android, Web, and React Native frontends. When using Lambda, you are responsible only for your code. Lambda manages the compute fleet that offers a balance of memory, CPU, network, and other resources to run your code. Because Lambda manages these resources, you cannot log in to compute instances or customize the operating system on provided runtimes. Lambda performs operational and administrative activities on your behalf, including managing capacity, monitoring, and logging your Lambda functions.

Sources :- 1. AWS Lambda 2. Understanding Lambda function scaling 3. AWS Lambda’s Major Limitations 4. What is AWS Lambda? 5. Lambda execution environments 6. Operating Lambda: Performance optimization – Part 1

Comments