At the outset, I'll say I'm not a huge fan of AWS Lambda. Nothing against it, I'm just not sold on all the hype and I'm suspicious about using it for more serious production systems. Not because I don't think it can work -- I know personally that it can -- but because I don't think it's the best choice. My view is that Lambda is a tool for rapid prototyping, but I'm open to being convinced otherwise.
Anyways, for better or worse, engineers sometimes have to work with tech someone else chose. It's a reality. It's part of the job. And you shouldn't half-ass your job. Not being in love with the tech is no excuse for half-assing your job (really, just don't half-ass anything in life).
Ok. So, what is Lambda, how's it work, etc? Not just high level, but like rigorously. I guess we should see what Amazon has to say. Summarizing https://docs.aws.amazon.com/lambda/latest/dg/welcome.html, Lambda
- lets you run code without managing servers
- only runs when needed, no charges when nothing is running
- code can run
a. in response to events
b. in response to an http requests
c. directly by invoking with AWS SDK
Basically, the pitch is that you only have to be concerned with your code and not worry about provisioning machines, deploying your app (at least not in "traditional" way). This is contrast to provisioning, paying for and deploying to EC2 instances.
The building blocks of Lambda applications are functions (which is I guess why people refer to it as "Faas", Functions as a Service). Functions process "Events". As the docs say, "You can send events to your function by invoking it with the Lambda API, or by configuring an AWS service or resource to invoke it."
- Functions are how you "run code" on Lambda
- The code runs in a "runtime" which is just an environment like a Python environment or a Node environment, etc. Right now, there's Node, Python, Ruby, Java, Go and .NET
- Events are JSON containing data for functions to process
You can create a function in the AWS Lambda console (presumably not what you would do when actually working on a real app). You open the console, choose "create a function", pick a name and click to create. You can scroll down to the editor and edit the default code right there in the console UI.
You can test the function right there by clicking the button (top right of page).
If you print or log things, it shows up in the "Function Logs" section
Also, if you go to CloudWatch, you'll see that a log group was created for your function. The logs/prints are there too:
That's it for now.Tags: AWS backend lambda python serverless