Lambda & Serverless Apps Flashcards

1
Q

Explain the AWS Lambda Pricing structure?

A
  • Pay per request and compute time (how long does the function run)
  • Pay per calls
    • Free tier of 1,000,000 AWS Lambda requests
    • After the free tier you pay $0.20 per 1 million requests
  • Pay per duration (in increments of 100ms)
    • 400,000 GB/s of compute time = free
    • == 400,000 seconds if function is 1 GB of RAM
    • == 3,200,000 seconds if function is 128 MB RAM
    • After that its $1.00 for 600,000 GB-seconds
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does lambda support multi-header values?

A
  • There is a setting on the Application Load Balancer (ALB) that supports this function.
  • When enabled, HTTP headers and query string parameters that are sent with multiple values are shown as arrays within the AWS lambda event and reponse objects.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What provides permission to invoke a function?

A

IAM Resource Policy

This is used when another SERVICE triggers the lambda fuction

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

What provides permissions for what a function can do?

A

IAM Execution Role

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

What are some recommendations for structuring your Lambda functions?

A
  • Seperate business logic from the handle method
  • Minimize the dependencies
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some recommendations/best practices for managing serverless applications in AWS?

A
  • Use a serverless application framework.
  • Use a SAM template to deploy your serverless applications rather than creating a template in AWS CloudFormation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some recommendations/best practices for organizing your code repository for serverless applications?

A

Organize your functions into services and give each service one deployment template and one code repository.

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

What are some reccommendation(s) / best practices for structuring your development environment for serverless applications?

A
  • Create seperate AWS accounts for each developer if you have management processes in place to handle it.
  • Seperate your production and non-production environemnts into different accounts.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the recommended test heirarchy for serverless applications?

A
  1. Local testing
  2. Remote integration tests
  3. Automated ntegration tests
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are some strategies for mocking out external services that your lambda function is talking to in order to isolate it and be able to test locally?

A
  • Use an exisiting mock library project like DynamoDB local or LocalStack
  • Create custom mocks
  • Don’t mock - use actual services
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why would you use a custom mocking strategy to help unit test your lambda function?

A
  • Allows you to effectively test Lambda functions chained together through multiple services
  • Note: This is expensive (lots of work on devs part)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How can you debug your serverless application?

A

Use your IDE debugger on the Docker container provided by SAM CLI

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

What is the difference between a language and runtime in AWS lambda?

A
  • The language is the specific language being used (i.e. Python, NodeJs etc) and runtime is the specifi version of that language.
  • As a developer you need to be sure that the runtime is compatible with AWS lambda.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the size limitations of lambda?

A
  • Uncompressed code and dependencies < 250 MB
  • Compressed function package < 50 MB
  • Total function packags in a region < 75 GB
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some workarounds for Lambda size limitations?

A
  • Look for smaller libraries.
  • Look to break down your function further into smaller steps.
  • A different language that offers a more compact solution.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the Ephemeral storage limitation of lambda?

A
  • < 512 MB
  • this is also refered to as the /tmp folder.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the maximum execution duration for a lambda function?

A

< 900 seconds (15 minutes)

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

What is the maximum number of concurrent lambda functions you can have?

A
  • You are limited to running 1000 lambda functions @ the same time.
  • Can set max limit to something lower using ‘reserved concurrency’ . This is recommended. When this limit is reached then throttling will occur.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is Lambda @Edge?

A
  • Used with CloudFront distribution
  • Can modify requests coming from either user or origin
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What services are asynchronous as it relates to lambda?

A
  • S3
  • SNS
  • CloudWatch Events / EventBridge
  • CodeCommit
  • CodePipeline
21
Q

What is a key characteristic of a serverless function?

A

It runs in response to events that trigger it.

22
Q

What AWS service can be used to trigger Lambda on a schedule?

A

CloudWatch

23
Q

What two arguments does a Lambda handler require?

A

event, context

24
Q

Records of Lambda function run logs are stored where?

A

CloudWatch

25
Q

What should a lambda function package contain?

A

Your function code and non-included libraries

26
Q

What is event source mapping is AWS lambda?

A
  • Records need to be polled from the source.
  • Events are read, and these events invoke a lambda function.
  • Used to process items from a stream or queue in services that don’t invoke Lambda functions directly.
27
Q

Is event mapping for AWS lambda synchronous or asynchronous?

A

synchronous

28
Q

How are event source mappings read from a stream or queue?

A
  • In batches
  • includes multiple items in the event that your function receives.
  • You can configure the size of the batch that the event source mapping sends to your function, up to a maximum that varies by service.
  • The number of items in the event can be smaller than the batch size if there aren’t enough items available, or if the batch is too large to send in one event and has to be split up.
29
Q

What services are used in event-mapping for AWS lambda?

A
  • Kinesis Data Streams
  • SQS and SQS FIFO Queues
  • DynamoDB Streams

This list can be broken into 2 categories: Streams and Queues

30
Q

Can the number of item in an event mapping be smaller than the batch size?

A
  • Yes, when the # of items are smaller than the batch size thats OK, or
  • if the batch is too large to send in one event and has to be split up.
31
Q

What are AWS Lambda Destinations?

A
  • allows you to route asynchronous function results as an execution record to a destination resource without writing additional code.
  • Previously, you needed to write the SQS/SNS/EventBridge handling code within your Lambda function and manage retries and failures yourself.
  • Destinations provide more useful capabilities over Dead Letter queues for asynchronous failure situations by passing additional function execution information, including code exception stack traces, to more destination services.
32
Q

How do you allow lambda functions access to VPC resources?

A
  • You must define a VPC ID, the subnets and the securty groups
  • Lambda will create an ENI (Elastic Network Interface) in your subnet(s)
  • AWSLambdaVPCAccessExecutionRole is needed to create the ENI
33
Q

Do lambda functions inside a VPC have access to the public internet?

A
  • Not by default.
  • Deploying a lambda funciton in a public subnet does NOT give the function internet access or public IP.
  • To give a lmbda function in a VPC internet access you must deploy it in a PRIVATE subnet and set up a NAT Gateway / Instance to provide internet access.
34
Q

If you have a computation heavy function, how can you increase that lambda functions performance?

A
  • Increase the RAM
  • Increasing the RAM increases the vCPU credits.
  • Should also decrease the duration of the function.
  • Note: The more memory you use the more you will pay so find a balance.
35
Q

If you have a function / job that runs for 15 minutes or more, is lambda the best service to use to run that function?

A

No. Lambda functions should run no more then 15 minutes. Other AWS services such as Fargate, ECS or EC2 would be a better option.

36
Q

Should connections to clients (RDS, SDK, etc.) be formed within a handler method, or outside of the handler method?

A

Outside the handler method. This way it only makes the connection once, ad the execution context will keep that connection alive for subsequent calls.

37
Q

Explain Lambda Versions

A
  • A new version of lambda is created each time a new function is published.
  • Versions are immutable.
38
Q

Explain lambda aliases

A

Aliases are mutable and point to an immutable version.

39
Q

Can a lambda alias point to another lambda alias?

A

No. An Alias can only point to a lambda version.

40
Q

What is the maximum size of environment variables in lambda?

A

4kb

41
Q

What is the min and max memory allocation sizes for lambda?

A

128kb - 10GB (64 MB increments)

42
Q

How do you declare a Lambda function with AWS CloudFormation?

A
  • Upload all the code as a zip to S3 and refer to the object in the cloudFormation’s AWS::Lambda::Function block.
  • Can also be refered to inline with CloudFormation but that only applies to simple functions that do not require any external dependencies.
43
Q

How can a Lambda function be integrated with an ALB?

A

With a target group

44
Q

What is the best way to send the result of an asynchronous Lambda function to SQS?

A

Use a destination

45
Q

What is AWS SAM?

A
  • Serverless Application Model
  • Its a framework for developing and deploying serverless applications.
  • Refered to as an AWS CLI tool and CloudFormation Macro –>
  • All configurations are in YAML code which gets compiled into a complex CloudFormation Template.
  • Requires only 2 commands to deploy to AWS
  • Can help you run Lambda, API Gateway, DynamoDB locally
46
Q

What header indicates that something is a SAM template?

A

A Transform Header:

ex. Transform: ‘AWS::Serverless-2016-10-31’

47
Q

What are the three resources that you can bring into your code using a SAM template?

A
  • Lambda Functions -> AWS : : Serverless : : Function
  • API Gateway -> AWS : : Serverless : : Api
  • DynamoDB -> AWS : : Serverless : : SimpleTable
48
Q

How do you package and deploy a SAM application?

A
  • AWS CloudFormation package using the CLI or SAM package
  • To deploy use cloudFormation deploy / sam deploy
49
Q

What is a Cloud Development Kit (CDK)?

A
  • Allows you to write Infrastructure as Code (IaC) using an imperative paradigm with your favorite language.
  • CDK transpiles into CloudFormation templates.