Skip to content

AWS ‐ Serverless Compute Services | Lambda Functions

FullstackCodingGuy edited this page Nov 8, 2024 · 5 revisions

image

What is serverless computing model?

  • Users will be focusing on their business objectives without worrying about the infrastructure hassle, as the responsibility is offloaded to the provider
  • Pay based on usage of resources
  • Auto scaling services when demand arises

AWS Lambda - Functions

  • Execute code without provisioning a server, it works like a microservice style function
  • Functions run on Highly available infrastructure
  • Compute resource administration is managed for you.

image

image

Options to work with Lambda

  • AWS Management Console -
  • AWS CLI
  • AWS SDKs
  • AWS CloudFormation
  • AWS SAM (Serverless application model)

Invoking a lambda function

  • AWS Lambda API - Manual way to call the function
  • Events from other aws services - automated way to call the function

Using lambda function

  • create functions
  • configure settings
    • basic settings
  • Protecting Information
    • Securing sensitive information
    • Environment variable encryption (not to store any sensitive information in the function), so the data is encrypted at rest and transit.
    • Function code portability (same code can be deployed to multiple env, ex: dev/test/stage)

Working with Functions

  • Best practice to use VPC (Virtual Private Cloud) Connections
    • It helps you to isolate various systems into a specific subnet, so that no need to expose all the systems, it can be put behind the subnet and only the selected systems can be exposed. (ex: database proxies)
  • Code Signing in the lambda to allow the trusted provider to execute the code.

Versions and Aliases

  • New copy of Function code and dependencies deployed in each version

  • Settings and environment variables are kept with the version

  • Amazon Resource Name (ARN) - resource identified, generated for each version of function

  • Aliases identify function versions, acts as pointers to function version, it is globally unique

Lambda Layer

  • Layer is a zip file archive, contains runtime, lib, configuration files, data

  • Code sharing and separation of responsibility

  • Layer is helpful to package image efficiently. It allows to package only code modifications instead of packing everything again

  • Multiple lambdas can use the same layer, which means, you can use common configurations, runtime, data

  • Functions deployed as zip archive (compiled code put into the zip, which then gets deployed)

  • Function deployed as container images as well

  • Function memory allocated between (128mb to 10gb)

  • VPC

    • Its a good practice to run lambda function with VPCs to isolate the resources, in case function needs to access private resources
    • When to configure VPC is, if you want to ensure the lambda function not accessible for public users, then keep the lambda within vpc
    • Create a specific interface VPC endpoint - in order to allow the resources to access the lambda within vpc
    • Use Elastic network interfaces to manage the traffic in the vpc by aws
  • Invocation methods

    • Lambda functions don't run continuously, it needs to be invoked to run the function
    • Ways to invoke Lambda
      1. Lambda Console
      2. Lambda API
      3. AWS SDK
      4. AWS CLI
      5. AWS Toolkits
    • Was to execute Lambda
      • Synchronously - Waiting for function execution, Direct Invocation
      • Asynchronously - no need to wait for completion
      • Triggers - when certain condition is met
      • Event source mapping (ex: trigger lambda function to execute automatically when an entry is added to s3 database)
  • Other Considerations

    • Monitoring function state, monitor the compute time of the fns (whether fns completing the operation within the intended time or not, if it runs long time, then it will incur more cost, hence the fn is inefficient)
    • Function scaling (keep the function simple, make the function do one thing and on thing well rather than a large function doing multiple things)
    • Error handling and retries (if a fn fails, let it fail gracefully and log the exception)
    • Lambda Extensions - to add additional things (ex: security)
    • Invoking function as container images

AWS Lambda Applications

  • It is a resource in aws, it consists of 1 or more lambda function, it is more than a function, it uses event sources to invoke those functions
  • Lambda application is deployed as a package just like the standard lambda function, it packages all components of the application as package
  • Integration with developer tools such as AWS CodePipeline, AWS CloudFormation to deploy the lambda application straight from code repository

Deploying Lambda Applications

  • AWS Serverless application repository
  • AWS CloudFormation
  • AWS CLI and SAM CLI
Clone this wiki locally