Sunday, June 6, 2021

AWS: Compute Services: Lambda

 

AWS Lambda is a compute service which lets you run your code on a high availability infrastructure and performs all the administration of the compute resources including server, OS, automatic scaling, monitoring, logging (CloudWatch), etc. 
You only pay for the compute time you consume; it is not chargeable when your code is not running. 
You can provision Lambda to run your code based on some trigger like data changes in S3, Dynamo DB, HTTP request, API calls, etc.

Below are the key concepts 

  • Function: Name of the function i.e. a resource you invoke to run your code

  • Runtime: Base execution environment

  • Event: JSON formatted document that contains data for a function to process. Lambda runtime converts an event in an object and passes it to function

  • Concurrency: Number of requests that your functions is serving at a given time. When a function is triggered to process the event, Lambda creates an instance to handle that request. Once that request is completed, the instance can take new request, however if a new request is received while processing earlier request, Lambda creates a new instance, increasing the concurrency 

  • Trigger: It is a resource or configuration that invokes a Lambda function  

Key points

  • Functions remains active for a few hours before it is recycled

  • Logs are sent to CloudWatch- functions output, execution start & end 

  • User local storage i.e. ‘/tmp’ directory and class level objects (avoid re-initialization) to increase performance

  • Deployment package i.e. source code ZIP archive file is created by console; for CLI or API, you need to create the ZIP; for compiled languages as well, you need to create ZIP manually

  • Layers let you manage your in-development code independently; functions can use layers created by you or by AWS or other customers

  • Reserved concurrency (dedicated pool) and provisioned concurrency (long running initialization)

  • Synchronous (req-resp) & asynchronous (queue) invocations cab configured

  • Event source mappings maintain a local queue for source batches (from SQS, DynamoDB, etc.) 

  • If your function throws an error during execution, runtime throws that error to invoker

  • Below are types of errors and error codes; retry can vary based on type of invocation

  • Invocation Errors (Before request reaches your function)

    • Request: too large request, invalid JSON, function doesn’t exist, wrong param, etc.

    • Caller: User or service doesn’t not have access to invoke the function

    • Account: max instances running, too frequent requests

  • Function Errors (Errors returned by function or runtime)

    • Function: Error thrown by function 

    • Runtime: function out of time, syntax error, function not able to parse JSON, etc.

  • API Gateway provides tools for creating web APIs that routes HTTP requests to Lambda functions (REST APIs as well as HTTP APIs) 

API References: https://docs.aws.amazon.com/lambda/latest/dg/API_Reference.html

No comments:

SpringBoot: Features: SpringApplication

Below are a few SpringBoot features corresponding to SpringApplication StartUp Logging ·          To add additional logging during startup...