Section 21: AWS Servless Lambda: Part 1 Flashcards

1
Q

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)

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is ec2 a serverless aws service

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Could this flow be serverless?

A

Yes, because all of those aws services are serverless.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Are there servers to manage when using Amazon Lambda virtual functions?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Do Amazon Lambda functions run on-demand

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Is scaling automated for Amazon Lambda?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Are Amazon Lambda functions limited by time/is it required that they have short execution times?

A

Yes, they are limited by time and it is required that they have short execution times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

With AWS lamda what do you pay for (do you pay for anything)?

A
  • you pay per request and compute time
  • free tier of 1,000,000 aws lambda requests and 400,000 GBs of compute time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Is aws lambda integrated with the whole aws suite of services?
  2. is aws lambda integrated with many programming languages?
  3. is aws lambda easy to monitor through aws CloudWatch?
A
  1. Yes
  2. Yes
  3. Yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Up to how many resources (GBs of RAM) can you get per function?
  2. will increasing RAM also improve CPU and network?
A
  1. up to 10 GB of RAM
  2. yes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What must be true of the Lambda Container Image?

A

The container image must implement the Lambda Runtime API

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Does aws lambda support:
node.js, JavaScript, Python, Java (including Java 8), C#, Golang, Ruby, Custom Runtime API

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Main Lambda Integratios

A
  • amazon s3
  • aws api gateway
  • aws cognito
  • aws dynamoDB
  • aws kinesis
  • aws sns
  • aws sqs
  • aws CloudFront
  • aws CloudWatch Events EventBridge
  • CloudWatch Logs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Walk me through an example of using lambda to generate and store image thumbnails after an image is uploaded to an S3 bucket.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are we looking at?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What’s a CRON job?

A

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.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

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?

A

Use CloudWatch Events EventBridge to trigger the running of an AWS Lambda function every hour. Boom. Serverless CRON job.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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?

A

After the free amount/period you pay $0.20 per 1 million requests, and you pay $1.00 for 600,00 GB-seconds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

with aws lambda do you pay per request or per duration?

A

both!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

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)?

A
  1. 400,000 seconds if function is 1GB of RAM
  2. 3,200,000 seconds if function is 128 MB of RAM
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

T/F: It is usually very cheap to run AWS Lambda so it’s very popular

A

T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

So what are synchronous invocations of lambda?

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Are these synchronous or asychronous invocations of lambda functions?

A

Synchronous (honestly i somewhate have issue with these being referred to as “synchronous invocations, but whatever)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What are examples of user invoked Lambda Synchronous Invocation Services?

A
  • elastic load balancing (app load balancer)
  • amazon api gateway
  • amazon cloudfront (Lambda@Edge)
  • Amazon S3 Batch
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What are examples of service invoked Lambda Synchronous Invocation Services?

A
  • amazon cognito
  • aws step functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Lambda integratoin with ALB: how do you expose a lambda function as an http endpoint?

A
  • you can use the application load balancer (or an api gateway)
  • the lambda function must be registered in a target group
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

what’s the flowchart for invokinng a lambda function through an api request?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

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.)

A

The requestContext.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What’s missing? Name the key, try to at least get close about the value.

A

“host”: “lambda-alb-12345678.us-east-2.elb.amazonaws.com”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

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

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

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?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

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

A
  1. “queryStringParameters”: { “myKey”: “val2”},
  2. “multiValueQueryStringParameters”: { “myKey”: [“val1”, “val2”] },
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

So say you send this to an ALB.
http://www.example.com?&myKey=val1&myKey=val2.

But your lambda function (a target of the ALB) only received (only paying attention to question relevant bit)

“queryStringParameters”: { “myKey”: “val2”},

Why didn’t “myKey”: “val1” also come in?

A

multi-value headers for the target group (lambda function) are not enabled by default. If you had enabled them, you would have gotten

“multiValueQueryStringParameters”: { “myKey”: [“val1”, “val2”] },

35
Q

Okay, Lambda Asynchronous Invocation.

What is asynchronous invocation and how does it relate to lambda?

A

asynchronous invocation is like that annoying thing react / javascript wants to do sometimes where it just starts running task a and then just takes off to activity b without waiting for activity a to end. So when something like S3 or SNS invokes a lambda function asychronously, it hands the event off to lambda (maybe to an event queue? still working out the details) and lambda handles things from there (including error handling and whether invocation records are sent to a downstream resource like SQS or EventBridge.)

36
Q

blank and blank invoke lambda functions asynchronously by sending events to lambda, who sticks them in a queue for processing by lambda functions.

A
  1. S3
  2. SNS
37
Q

What’s the flow from S3 to lambda function?

A
38
Q

you don’t need to wait for the results and you are very concerned with having a fast processing time. Do you use synchronous or asynchronous invocation of lambda functions?

A

Asynchronous.

39
Q

T/F
lambda manages the function’s async event queues and attempts to retry on errors.

A

T

40
Q

Where can you go to look to see if lambda wasn’t able to add an event to the queue? (when you triggered the function via the cli)

A

The error message wil appear in the command output. Honestly i’m still fuzzy on where this command output is supposed to be showing up. Based on surrounding paragraph, I beleive they mean the output shows up in the cli.

41
Q

To invooke a lambda function asychronously, what value do you pass for cli flag –invocation-type

A

“Event”

42
Q

A Lambda function tried to process an event but failed. What happens next?

A

Lambda attempts to run the function twice more, with a one minute wait between the first two attempts, and two minutes between the second and third attempts.

43
Q

T/F if a lambda function retries to the process the same event, you’ll see duplicate log entries in CloudWatch Logs.

A

T

44
Q

Say you want to set lambda up to send invocation records to another service (not cloudwatch logs, which i beleive, though everything is a little fuzzy so you should check, happens by default.). To what other destinations could you send the async invocation records?

A
  1. SQS (standard, not fifo)
  2. SNS (standard, not fifo)
  3. lambda function
  4. eventbridge event bus
45
Q

You want a dead letter queue for failed lambda function (event?) processing (you need the correct iam permissions, btw). Can you do this? how?

A

you can configure a standard Amazon SQS queue or standard Amazon SNS topic as a dead-letter queue for discarded events. For dead-letter queues, Lambda only sends the content of the event, without details about the response.

46
Q

T/F

As an alternative to an on-failure destination, you can configure your function with a dead-letter queue to save discarded events for further processing. A dead-letter queue acts the same as an on-failure destination in that it is used when an event fails all processing attempts or expires without being processed. However, a dead-letter queue is part of a function’s version-specific configuration, so it is locked in when you publish a version. On-failure destinations also support additional targets and include details about the function’s response in the invocation record.

A

T

47
Q

Can you configure separate destinations for events that are processed successfully, and events that fail all processing attempts?

A

yes (the destination for failed attempts could also be a dead letter queue)

48
Q

W

what the flow for having an s3 bucket new file event trigger a lambda function and send failed function running attempts to a dead letter queue?

A
49
Q

From the standpoint of the certification, we need to know how lambda works with what aws services?

A
  1. S3
  2. sns
  3. cloudwatch events or event bridge
50
Q

What aws services are invoke lambda asynchronously? (you don’t at all need to memorize this, maybe just read the list)

A
  • s3
  • sns
  • cloudwatch events/eventbridge
  • code commit (codecommit trigger: new branch, new tag new push)
  • codepipeline (invoke lambda function during the pipeline, lambda must callback)
  • cloudwatch logs (log processing)
  • SES (simple email service)
  • cloud formation
  • config
  • IoT
  • IoT Events
51
Q

Name two ways in which CloudWatch Events or EventBridge are integrated with Lambda.

A
  1. do a serverless CRON or a rate. Create an eventbridge rule, and then every hour, trigger a lambda functoin to perform a task.
  2. create a codepipeline eventbridge rule to detect every time codepipeline state changes.
52
Q

S3 and Lambda: what kind of s3 events are often used to asynchronously trigger lambda functions?

A
  • S3:ObjectCreated
  • S3:ObjectRemoved
  • S3:ObjectRestore
  • S3:Replication
53
Q
  1. Can you create an event notification that incorporates a based on S3 object name prefix (images/) and/or suffix (.jpg)?
  2. What do you need to do if there’s a space in the prefix name?
  3. what happens if there are any other special characters in the value of the prefix or suffix (not sure what special characters could be in a suffix but oh well)
  4. Can you use wildcards anywhere?
A
  1. yes
  2. replace it with a ‘+’ in the notification configuration
  3. enter them in URL-encoded (percent-encoded) format.
  4. no
54
Q

Whats a popular s3-lambda use case? (hint: it’s about when images are uploaded to s3)

A

generate thumbnails of images uploaded to s3

55
Q

So, if two writes are made to a single non-versioned s3 object at the same time, it is possible that only a single event notification will be sent. What can you do to ensure an event notification is sent for every successful write?

A

Enable versioning on your bucket.

56
Q

What’s a popular S3-lambda event pattern for if you want to save metadata somewhere when someone uploads a new file to an s3 bucket?

A
57
Q

What is an event source mapping (as it relates to lambda)?

A

an event source mapping is a lambda resource that reads from an event source and invokes a lambda function. You can use event source mappings to process items from a stream or queue in services that don’t invoke lambda functions directly.

58
Q

Does event source mapping (as it relates to lambda) rely on synchronous or asynchronous invocation?

A

Synchronous. The lambda resource itself is going out to the event source to see if there are any new records / items that need processing. It’s not doing this when it knows new items exist, it’s doing this at regular, preset intervals to see if new items exist.

59
Q

What are the big services that lambda reads events from? (you do need to guess at least the bolded items).

A
  • amazon dynamodb
  • amazon kinesis
  • amazon mq
  • amazon managed streaming for apache kafka (msk)
  • self-managed apache kafka
  • amazon simple queue service (standard and fifo)
  • amazon documentDB (with mongoDB compatibility) ()
60
Q

Lambda and Streams (kinesis and dyanmoBD):

Polling and batching streams:

Lambda reads records from the data stream and invokes your function synchronously with an event that contains stream records. Lambda reads records in batches and invokes your function to process records from the batch, each batch contains records from a single shard/data stream.

Are processed items removed from the kinesis data stream?

A

No, this means other functions or consumers (not your lambda function) can process them too. idk, maybe later figure out how’d you’d keep your lambda function from running for the same item multiple times.

61
Q

Lambda and Streams (kinesis and dyanmoBD):

For kinesis and dynamoDB streams, an event source mapping creates an iterator for each shard in teh stream and processes items in each shard in order. you can configure the event source mapping to read blank 1 or blank 2.

A
  1. only new items that appear in the stream
  2. to start with older items (by indicating a starting timestamp).
62
Q

Lambda and Streams (kinesis and dyanmoBD): T/F:

you cannot process multiple batches in parallel.

A

False. You can process multiple batches in parallel: up to 10 batches per shard, and in-order processing is still gauranteed for each partition key.

63
Q

Lambda and Streams (kinesis and dyanmoBD):

you lambda function keeps polling a data stream that only has one record and then invoking your function with just the one records (you have low traffic or something) how can you avoid invoking the function with a single, or a small, number of records?

A

Configure a batching window. With one of these, you can tell the event source to buffer (continue reading records from the event source, at least in this context) records for up to 5 minutes, or until the batch reaches the payload limit of 6MB (non-configurable), or until the batch contains a certain number of records.

64
Q

Lambda and Streams (kinesis and dyanmoBD):

Lambda event source mappings process each event at least once, and duplicate processing of batches can occur. What can you do avoid potential issues related to duplicate events?

A

You can make your function code idempotent (write your code in such a way that it can identify whether an event/record/item was processed before. one way of doing this might be by assigning each event/record/item an id and sticking that id in some database.). In general, making a function idempotent also means validating inputs.

65
Q

Lambda and Streams (kinesis and dyanmoBD): T/F:

By default, if your function returns an error, the entire batch is reproccessed until the function succeeds, or the items in the batch expire.

A

T

66
Q

Lambda and Streams (kinesis and dyanmoBD):

With the default settings, Lambda might want to keep retrying a failed record for a week. To avoid this, you can configure the event source mapping to: blank 1, blank 2, blank 3

A
  1. discard old events
  2. restrict the number of retries
  3. split the batch on error (turn one batch of ten into two batches of 5)
67
Q

Lambda and any type of event source mapping

To retain a record of discarded batches, what can you do? Can you retain a record of successfully processed batches?

A

Configure a failed-event destination. This way, lambda sends a document to the destination queue or topic with details about the batch. No, you cannot retain a record of successfully processed batches fo revent source mapping invocations. You can, however, retain records of both successful and failed invocations when the invocatoin is asynchronous.

68
Q

Lambda and SQS:

Does lambda event source mappings support standard queues, fifo queues, or both

A

both

69
Q

lambda and sqs:

What happens when your function successfully a processes a batch?

A

lambda deletes the associated messages from the queue (i beleive by using SQS API action DeleteMessage. Not sure whether this is behavior preconfigured, but it’s at least possible.).

70
Q

Lambda and SQS: T/F:

when lambda reads a batch, the messages stay in the queue but are hidden for the length of the queue’s visibility timeout. if your function encounters an error while processing a batch, all messages in that batch become visible in the queue again after the visiblity timeout expires. for this reason, your functoin code must be able to process the same message multipe times without unintended side effects.

A

T

71
Q

lambda and sqs:

Recommended length of time to set the queue visiblity timeout to blank the timeout of your lambda function?

A

6 times

72
Q

lambda and sqs:

Do you set up the dead letter queue (if you want one) on the sqs queue, or in lambda?

A

on the SQS queue. DLQ for labda is only for async invocations.

73
Q

lambda and sqs:

  1. does event source mapping using long polling to poll sqs?
  2. You have to specificy the desired batch size - what is the range of size options?
A
  1. long polling
  2. 1-10 batches
74
Q

Lambda and SQS: T/F:

Occassionally, the event source mapping might receive the same item from teh queue twice (not sure if this is limited to standard queues), even if no functoin error occurred.

A

True. It’s not mentioned, but i’m guessing you’d want to use function idempotency again here to avoid this.

75
Q

Lambda and SQS:

  1. For SQS queues, does lambda scale up to the number of active message groups?
  2. for standard queues, are items processed in order?
  3. does lambda scale up to process a standard queue as quickly as possible?
A
  1. yes
  2. not necessarily
  3. yes
76
Q

Lambda event mapper scaling:

For kinesis data streams and dyanmoDB streams:
2. 1. how many lambda invocations can occur per stream shard (i assume they meat at a time)? (i also suspect this question is asking about default behavior.)
2. if you use parallelization, up to how many batches can be processed per shard simultaneously?

A
  1. 1
  2. 10
77
Q

lambda event mapper scaling:

For SQS Standard:
1. how many instances per minute can lambda add to scale up?
2. up to how many batches of messages can be processed simultaneously?

A
  1. 60
  2. 1000
78
Q

lambda event mapper scaling:

For SQS FIFO:
1. Will messages with the same groupID be processed in order?
2. Does Lambda function scale to the number of active message groups?

A
  1. yes
  2. yes
79
Q

What a lambda event object (describe it in terms of an eventBridge rule triggering the creation of an event that in turn gets passed to a lambda function)

A

The event object is the json-formatted document that contains the data that the function is going to process. Then, if your lambda function was using a python runtime, taht event object would get converted into a dictionary and you’ll be able to get the important information from the event object that way.

80
Q

What a lambda context object (describe it in terms of an eventBridge rule triggering the creation of an event that in turn gets passed to a lambda function)

A

The context object is the json-formatted document that provides information about the invocation itself and the runtime environment. It looks like it’s generated by Lambda after lambda receives the event object. It looks like lambda uses information from the event object (the invoked_function_arn key value pair) when creating the context object. Then, if your lambda function was using a python runtime, that context object would get converted into a dictionary and you’ll be able to get the important information from the event object that way.

81
Q

Which of the following yellow boxes contain values (well, keys in the code, but they end up being values) from the event dictionary (aka the event object), and which contain values from the context dictionary (aka the context object)?

You don’t have to know the keys. though bonus points for trying!

A
  1. event.source
  2. event.region
  3. context.aws_request_id
  4. context.function_name
  5. context.invoked_function_arn
  6. context.memory_limit_in_mb
  7. context.log_stream_name
  8. context.log_group_name
82
Q
  1. can you define a destination for both sucessful and failed events (function running of them, probably) when an asychronous invocation was used?
  2. can you do the same thing for event source mappings?
A
  1. yep
  2. nope. You can only define a destination/DLQ (though destination is preferrred) for discarded event batches
83
Q
  1. Does aws reccommend you use destinations or DLQs for failed events/batches? 2. Could you use both at the same time?
A
  1. aws reccommends you use destinations, not DLQs.
  2. you can use both at the same time (idk why you would - maybe to transition slowly?)