Pranav Soni

Entrepreneur | Software Engineer | Learner

AWS Lambda

Published on 2025-02-13
awslambdaserverlessinfrastructurecloud101example

Aim πŸ₯…

  • Understand what is a AWS Lambda & Lambda functions in and how to use them

TL;DR 🩳

  1. AWS Lambda is used to run serverless code
  2. AWS Lambda functions are used to organize the code
  3. Saves money, pay only for compute time consumed
  4. Lambda function is the key
    1. In python, it has lambda_handler that handles the main endpoints
      1. This functions should not be renamed
    2. Now this lambda handler takes in 2 args, event & context, event has data for function to process, context is send automatically and is useful for monitoring with logs

What's on the plate 🍽?

  • AWS Lambda can be used to run serverless code.
    • Just have to supply code!
  • Lambda functions are used to organize the code.
  • Saves money, only when a function is called we are charged, pay for compute time that you consume
  • How to use Lambda Functions?
    • Just have a simple code with a function lambda_handler
      • defined as: def lambda_handler(event, context) -> some json response:
      • that's it!
  • Key concepts:
    • lambda_handler
      • handler function is the entry point to the code. When the function is invoked, Lambda runs this method
        • "Be sure not to edit the name of this Python function. If you do, Lambda won’t be able to run your code when you invoke your function."
    • The Lambda event object:
      • lambda_handler takes two args, event & context
        • event: JSON formatted doc with data for function to process
        • context: Passes automatically, contains info about function invocation and execution env. Can be used for monitoring by outputing info about function's invocation. like logger.info(f"CloudWatch logs group: {context.log_group_name}")

References πŸ“˜

  • https://docs.aws.amazon.com/lambda/latest/dg/welcome.html
  • https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html