21. Lambda **IMPORTANT** Flashcards

1
Q

When should you use Lambda@Edge?

A

Whenever we need to integrate Lambda with a CloudFront distribution or for the following:

  1. search engine optimization
  2. web security + privacy
  3. dynamic web app at edge
  4. user tracking + analytics
  5. user authentication + authorization
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When can you use Lambda@Edge to change CloudFront requests and responses?

A
  1. After CF receives a request from a viewer
  2. Before CF forwards the request to the origin
  3. After CF receives the response from the origin
  4. Before CF forwards the response to the viewer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the best way to give other accounts and AWS services permission to use your Lambda resources?

A

Use resource-based policies to give other accounts and AWS services permission to use your Lambda resources.

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

True or False: Deploying a Lambda function in a public subnet does not give it internet access or a public IP.

A

True

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

True or False: Deploying a Lambda function in a private subnet does not give it internet access or a public IP.

A

Depends. Deploying a Lambda function in a private subnet gives it internet access if you have a NAT Gateway / Instance.

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

What is the default Lambda function timeout?

A

3 seconds

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

Where should you store reusable, temporary context for Lambda?

A

/tmp directory

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

Where should you store persistent objects (not temporary) for Lambda?

A

S3

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

What do you set to throttle/limit a Lambda function?

A

Reserved concurrency at the function level

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

What is the Lambda concurrency limit?

A

1,000 concurrent executions

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

How do you use function dependencies in Lambda?

A

Install the packages alongside your code and zip it together.

Upload the zip to Lambda if less than 50MB, else to S3 first

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

True or False: Aliases can reference aliases.

A

False.

Aliases cannot reference aliases (only versions)

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

What is the correct way to connect a Lambda function to an RDS instance?

A

Configure Lambda to connect to VPC with private subnet and Security Group needed to access RDS

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

How do you increase CPU or network on Lambda?

A

The more RAM you add, the more vCPU you get

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

How is Lambda priced?

A

pay per call (first 1mil free)
and per duration (first 400,000GB-sec per month free)

usually very cheap to run Lambda

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

What is a synchronous invocation?

A
  • you wait for the function to process the event and return a response
  • error handling must happen client side (retries, exponential backoff, etc)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Lambda communicates via synchronous invocation with which services?

A
CLI
SDK
API Gateway
Application Load Balancer
CloudFront (Lambda@Edge)
Cognito
Step Functions
Kinesis Data Firehose
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do you expose a Lambda function as an HTTP(S) endpoint?

A
  1. use the ALB or an API Gateway
  2. Lambda function must be registered in a target group

ALB converts the HTTP to JSON for Lambda (and converts it back)

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

How does AWS support multi-header values?

A

An ALB setting that takes HTTP headers and query string parameters with multiple values and forms them into arrays for Lambda events and response objects

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

What is an asynchronous invocation?

A
  • Lambda queues the event for processing and returns a response immediately
  • Lambda attempts to retry on errors (3 tries total)
  • will see duplicate log entries in CloudWatch Logs
  • can create DLQ in SQS or SNS for failed events
21
Q

When should you use asynchronous invocations?

A

When you want to speed up processing because you don’t need to wait for the result

22
Q

Lambda communicates via asynchronous invocation with which services?

A

S3
SNS
EventBridge

23
Q

What are the 2 ways to setup S3 Event notifications to send to Lambda?

A
  1. S3 –> SQS –> Lambda

2. S3 – (asynchronous) –> Lambda

24
Q

By default, what happens if your Lambda function returns an error on a batch?

A

The entire batch is reprocessed until the function succeeds or the items in the batch expire

25
Q

The DLQ for Lambda only works for what type of invocations?

A

asynchronous

26
Q

How should you setup Lambda to pull from SQS?

A
  1. Lambda Event Source Mapping will poll SQS (Long Polling)
  2. Setup a DLQ on the SQS queue, not Lambda OR use a Lambda destination for failures
27
Q

When processing in-order FIFO queues, Lambda scales up to what?

A

For FIFO queues, Lambda scales up to the number of active message groups. Messages with the same GroupID will be processed in order.

28
Q

When you use an event source mapping to invoke your function, what role does Lambda need?

A

When you use an event source mapping to invoke your function, Lambda uses the execution role to read event data

29
Q

When do you use a Resource Based Policy on Lambda?

A

When our function is invoked by other services

30
Q

When should you use Resource Based Policies?

A

Use resource-based policies to give other accounts and AWS services permission to use your Lambda resources (similar to S3 bucket policies on S3)

31
Q

How do you setup Lambda to write to CloudWatch logs?

A

It is automatic so long as your AWS Lambda function has an execution role with an IAM policy that authorizes writes to CloudWatch logs

32
Q

What are the 3 environment variables for Lambda to communicate with X-Ray?

A

AWS_XRAY_DAEMON_ADDRESS
_X_AMZN_TRACE_ID
AWS_X_RAY_CONTENT_MISSING

33
Q

What is the AWS_XRAY_DAEMON_ADDRESS environment variable provide?

A

The X-Ray Daemon IP_ADDRESS:PORT

34
Q

True or False: By default, your Lambda function is launched inside your own VPC.

A

False.

By default, your Lambda function is launched outside your own VPC. It is launched in an AWS-owned VPC.

35
Q

True or False: Deploying a Lambda function in a public subnet does not give it internet access or a public IP.

A

True.

36
Q

How do you access AWS services privately without a NAT?

A

VPC endpoints

37
Q

What should you use to maintain Lambda connection to databases or HTTP clients?

A

Lambda Execution Context

the execution context is a temporary runtime environment that initializes any external dependencies of your lambda code (includes the /tmp directory)

38
Q

What is the max size of the Lambda /tmp directory?

A

512 MB

39
Q

What do you set to throttle a Lambda function?

A

Reserved concurrency

40
Q

How do you allocate threads for a Lambda function before it is invoked (in advance)?

A

Provisioned concurrency

41
Q

What property do you set to declare a Lambda function inline of a CloudFormation template?

A

Code.ZipFile

42
Q

When should you use Lambda Layers?

A

To externalize dependencies to re-use them

43
Q

_____ are “pointers” to Lambda function versions.

A

Aliases

We can define a “dev,” “test,” “prod” aliases and have them point to different lambda versions. Used for blue/green deployment

44
Q

What is the Lambda environment variable size limit?

A

4 KB

45
Q

What is the max Lambda memory allocation?

A

3008 MB (3 GB)

lowest is 128 MB, 64 MB increments

46
Q

What is the max Lambda function deployment size (compressed .zip)?

A

50 MB

47
Q

What is the max Lambda function uncompressed deployment size (code + dependencies)?

A

250 MB

48
Q

You are looking to invoke an AWS Lambda function every hour (similar to a cron job) in a serverless way. Which event source should you use for your AWS Lambda function?

A

CloudWatch Events

49
Q

Which services require an event source mapping?

A

DynamoDB Streams
Kinesis Streams
SQS

To process items from a stream or queue, you can create an event source mapping. An event source mapping is a resource in Lambda that reads items from an Amazon SQS queue, an Amazon Kinesis stream, or an Amazon DynamoDB stream, and sends them to your function in batches. Each event that your function processes can contain hundreds or thousands of items.