Aim π₯
- Understand what is a AWS Lambda & Lambda functions in and how to use them
TL;DR π©³
- AWS Lambda is used to run serverless code
- AWS Lambda functions are used to organize the code
- Saves money, pay only for compute time consumed
- Lambda function is the key
- In python, it has
lambda_handler
that handles the main endpoints- This functions should not be renamed
- 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
- In python, it has
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!
- defined as:
- Just have a simple code with a function
- 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."
- handler function is the entry point to the code. When the function is invoked, Lambda runs this method
- The Lambda event object:
lambda_handler
takes two args,event
&context
event
: JSON formatted doc with data for function to processcontext
: Passes automatically, contains info about function invocation and execution env. Can be used for monitoring by outputing info about function's invocation. likelogger.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