Section 21: AWS Servless Lambda: Part 1 Flashcards
T/F:
* Servless was pioneered by aws lambda but now also includes anything that’s managed: “databases, messaging, storage, etc.”
* Serverless is a new paradigm in which the developers don’t have to manage servers anymore - they just deploy code.
* initially, serverless == FaaS (Function as a Service)
T
Name some big serverless aws services.
Hints:
* the list in steph’s slide is 10 services long - two start with ‘amazon’ and 8 start with ‘aws’
* as a(g)cdfk(df)ls(s)s
- amazon aurora serverless
- amazon s3
- aws api gateway
- aws cognito
- aws dynamoDB
- aws fargate (not in a later slide about being a main one)
- aws kinesis data firehose
- aws lambda
- aws sns & sqs
- aws step functions
Is ec2 a serverless aws service
I don’t think so. I think the point of serverless (by steph’s version of aws standards) is that i don’t even worry about like ram/cpu/whatever else is involved in actually configuring my computer (server). With ec2, I do have to set those things (there might be an option for letting aws determine that, but idk). I also don’t remember who’s in charge of upgrades for ec2. Maybe it’s aws?
OKAY literally the next section was about how ec2 is an example of that which is not serverless. The slide says that EC2 is a virtual server in the cloud, limited by RAM and CPI, continously running, scaling means intervention to add/remove servers.
Could this flow be serverless?
Yes, because all of those aws services are serverless.
Are there servers to manage when using Amazon Lambda virtual functions?
No
Do Amazon Lambda functions run on-demand
yes
Is scaling automated for Amazon Lambda?
Yes
Are Amazon Lambda functions limited by time/is it required that they have short execution times?
Yes, they are limited by time and it is required that they have short execution times.
With AWS lamda what do you pay for (do you pay for anything)?
- you pay per request and compute time
- free tier of 1,000,000 aws lambda requests and 400,000 GBs of compute time.
- Is aws lambda integrated with the whole aws suite of services?
- is aws lambda integrated with many programming languages?
- is aws lambda easy to monitor through aws CloudWatch?
- Yes
- Yes
- Yes
- Up to how many resources (GBs of RAM) can you get per function?
- will increasing RAM also improve CPU and network?
- up to 10 GB of RAM
- yes
What must be true of the Lambda Container Image?
The container image must implement the Lambda Runtime API
Does aws lambda support:
node.js, JavaScript, Python, Java (including Java 8), C#, Golang, Ruby, Custom Runtime API
Main Lambda Integratios
- amazon s3
- aws api gateway
- aws cognito
- aws dynamoDB
- aws kinesis
- aws sns
- aws sqs
- aws CloudFront
- aws CloudWatch Events EventBridge
- CloudWatch Logs
Walk me through an example of using lambda to generate and store image thumbnails after an image is uploaded to an S3 bucket.
What are we looking at?
a Serverless CRON job. A serverless
A CRON job is a job that runs regularly (CRON from chronology probably though why they’d leave out the H i have no idea to basically run a job at regular intervals). What’s a serverless CRON job? A CRON job that runs on/off serverless services (like cloudwatch events eventBridge and lambda)
What’s a CRON job?
A CRON job (probably industry term) is a job that runs regularly (CRON from chronology probably though why they’d leave out the H i have no idea to basically run a job at regular intervals.)
So CRON is a way on your ec2 instances, for example, to generate jobs every 5 minutes (or on any schedule). But with EC2 you’re running this cron job on a virtual server, so you have to manage all that stuff and your ec2 instances are still running, even if your cron job isn’t running. So what would be a better (think: serverless) way to do this?
Use CloudWatch Events EventBridge to trigger the running of an AWS Lambda function every hour. Boom. Serverless CRON job.
So, as we mentioned before the first 1 million requests (i assume requests are like things that could trigger a lambda function, or requests a lambda function might make to another service) are free. Additionally, the first 400,000 GB-seconds of compute time per month are free (we’ll cover some examples later). What’s the cost (remember, cost is call cost + duration cost) after that?
After the free amount/period you pay $0.20 per 1 million requests, and you pay $1.00 for 600,00 GB-seconds.
with aws lambda do you pay per request or per duration?
both!
With Lambda cost (after free request count/initial monthly GB–sec allotment) is (per call + per duration). The duration is 400,000 GB-seconds of compute time per month.
1. How many seconds would you get if you only had one function that relied on 1GB of RAM?
2. How many seconds would you get if you only had one function that relied on 128 MB of RAM? (1 GB is 1000 MB)?
- 400,000 seconds if function is 1GB of RAM
- 3,200,000 seconds if function is 128 MB of RAM
T/F: It is usually very cheap to run AWS Lambda so it’s very popular
T
So what are synchronous invocations of lambda?
Synchronous invocations are ones where you trigger a lambda function (maybe through the CLI, or SDK, or API Gateway, or an Application Load Balancer) and you’re waiting for the results to be returned to you. Any errors that come back to you must be handled on teh client side (so you have to decide whether you’re going to click the retry button or do an exponential backoff or whatever).
Are these synchronous or asychronous invocations of lambda functions?
Synchronous (honestly i somewhate have issue with these being referred to as “synchronous invocations, but whatever)
What are examples of user invoked Lambda Synchronous Invocation Services?
- elastic load balancing (app load balancer)
- amazon api gateway
- amazon cloudfront (Lambda@Edge)
- Amazon S3 Batch
What are examples of service invoked Lambda Synchronous Invocation Services?
- amazon cognito
- aws step functions
Lambda integratoin with ALB: how do you expose a lambda function as an http endpoint?
- you can use the application load balancer (or an api gateway)
- the lambda function must be registered in a target group
what’s the flowchart for invokinng a lambda function through an api request?
So when you make a json request payload to get to a lambda function you need al lthe usual stuff, like an httpMethod and a path and query string parameters, headers (might ask about the more interesting headers later), body (even if it’s just an empty string). But you also need something else in the request payload. What is it? (Recommend you explain by example.)
The requestContext.
What’s missing? Name the key, try to at least get close about the value.
“host”: “lambda-alb-12345678.us-east-2.elb.amazonaws.com”
So previously we’ve talking about how ALB can support multi header values (for example, http://example.com/path?name=foo&name=bar). When you enable multi-value headers, http
T/F can an ALB transform a regular api request into a json request, so that a lambda function gets the JSON it’s expecting?
Yes
So say you send the api below to an ALB. What comes back in the query string parameters (relevant bits) if:
1. you have not enable multi-value headers for the target group (lambda function) (it’s not enabled by default).
2. you have enabled multi value headers for the target group (lambda function)
http://www.example.com?&myKey=val1&myKey=val2
- “queryStringParameters”: { “myKey”: “val2”},
- “multiValueQueryStringParameters”: { “myKey”: [“val1”, “val2”] },