Serverless And Lambda Flashcards

1
Q

when you use serverless services

A

it’s not that you don’t have servers anymore, it’s just that you don’t manage them.

You just deploy code and originally, you just deploy it functions.

So initially serverless meant Function as a Service,
or FaaS.

But now serverless means a lot more. So in the beginning, serverless was pioneered by AWS Lambda
but now also includes anything that is remotely managed.

So databases, messaging, storage, as long as you don’t provision servers.

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

serverless in AWS

A
  1. we have our users and they would get for example,
    static content for from our S3 buckets delivered as a website’s or CloudFront plus S3.
  2. Then we would login with Cognito, this is where our users would have their identity stored.
  3. they would invoke your REST API through the API gateway
  4. the API gateway would invoke Lambda functions
  5. Lambda functions would store and retrieve data from DynamoDB.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

reference architecture for serverless applications.

A

Lambda DynamoDB, Cognito, API Gateway, Amazon S3, but also SNS and SQS, Kinesis Data Firehose, because again it scales based on the throughput you have you just pay for what you use and you don’t provision servers, Aurora Serverless, when your Aurora database scales on demand without you managing servers,
Step functions, Fargate

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

Lambda

A

virtual functions, no servers to manage.

we just provision the code and the functions run.

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

Lambda execution period

A

This is limited by time,

short executions of up to 15 minutes,

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

Lambda on-demand

A

they run on-demand. When you don’t use Lambda, your Lambda function is not running, and you only are going to be billed when your function is running
and it will run on-demand when it gets invoked,

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

Lambda scaling

A

scaling is automated.

If you need more Lambda functions, occurrences,
then automatically, AWS will provision for you
more Lambda functions.

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

Lambda payment

A

You’re going to pay for the number of requests
Lambda receives, so the number of invocations,
and your compute time, so how long Lambda was running for.

free tier on Lambda is 1 million Lambda requests,
and 400,000 gigabyte-seconds of compute time.

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

Lambda resources per function

A

if you want to provision more resources per function,

you can provision up to three gigabytes of RAM per function

if you increase the RAM of your function, then it will also improve the quality and performance of your CPU and network.

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

Lambda language support

A

Node.js, so JavaScript, Python, Java, and this is Java 8 compatible, C# or .NET Core, Golang, C# and Powershell, Ruby, and there is a new API called the Custom Runtime API, where you can run pretty much any language on Lambda, but it has to be community supported, and one of these example is, for example,
the Rust language.

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

The one thing that does not run on Lambda is

A

Docker

if in the exam you are asked, I want to run a Docker container on AWS, you have to think ECS or Fargate.

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

Lambda - API Gateway integration

A

to create a REST API, and they will invoke our Lambda functions.

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

Lambda - Kinesis integration

A

Kinesis will be using Lambda to do some data transformations on the fly.

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

Lambda - DynamoDB integration

A

DynamoDB will be used to create some triggers,

so whenever something happens in our database,

a Lambda function will be triggered.

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

Lambda - S3 integration

A

a Lambda function will be triggered anytime, for example,

a file is created in S3.

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

Lambda - CloudFront integration

A

this will be Lambda@Edge,

17
Q

Lambda - CloudWatch integration

A

CloudWatch Events or EventBridge, this is whenever things happen in our infrastructure on AWS and want to be able to react to things, for example,

say, we have a CodePipeline state changes, and we want to do some automations based on it, we can use a Lambda function.

CloudWatch Logs to stream these logs wherever you want.

18
Q

Lambda - SNS integration

A

SNS to react to notifications

19
Q

Lambda - SQS integration

A

SQS to process messages from your SQS queues.

20
Q

Lambda - Cognito integration

A

to react to whenever, for example, a user logs into your database.

21
Q

serverless thumbnail creation

A

we have an S3 bucket, and we want to create thumbnails on the fly, so there will be an event, which is, that the new image will be uploaded in Amazon S3.

This will trigger through an S3 event notification,
a Lambda function, which will have code to generate a thumbnail.

That thumbnail may be pushed and uploaded into another S3 bucket or the same S3 bucket, which would be a smaller version of that image,

and also, our Lambda function may want to insert some data into DynamoDB, around some metadata for the image, for example, the image name, size, creation date, et cetera, et cetera.

And so thanks to Lambda, we’ve automated and had a reactive architecture to the event of new app, new images being created in S3.

22
Q

serverless CRON job

A

if you run CRON on a virtual server, so an EC2 instance, while your instance is not running,
or at least your CRONs are not doing anything,
then your instance time is wasted.

you can create a CloudWatch event rule, or an EventBridge rule, that will be triggered every one hour.

And every one hour, it will be integrated
with a Lambda function that will perform your task.

So this is a way to create a serverless CRON,
because in this example, CloudWatch Events is serverless, and Lambda functions are serverless too.

23
Q

Lambda pricing example

A

you pay per calls, the first 1 million requests are free,
and then you’re going to pay 20 cents for extra 1 million requests,

Then you’re going to pay per duration in increments of 100 milliseconds. So you get the first 400,000 gigabyte-seconds of compute time per month for free.

And then what that means is gigabyte-seconds that,
it means you get 400,000 seconds of execution,
if the function has one gigabyte of RAM.
That means you get eight times as more seconds,
if the function has eight times as less RAM,
so 128 megabyte of RAM.

And after that, you’re going to pay $1 for 600,000 gigabyte-seconds.

24
Q

Lambda limitations in execution (EXAM)

A
  1. memory allocation is between 128 megabytes to 3000 megabytes. And this is in 64 megabytes increments. When we increase the memory,
    then we have more vCPU
  2. maximum execution time is 900 seconds, which is 15 minutes,
  3. we can only have up to four kilobytes of environment variables
  4. disk capacity in “the function container” (/tmp): 512 MB
  5. We can have up to 1000 concurrent executions
    other than the functions. (can be increased)
25
Q

Lambda limitations in deployment (EXAM)

A
  1. max size for your compressed .zip is 50 MB
  2. Size of uncompressed deployment (code + dependencies) : 250 MB
  3. Can use /tmp directory to load other files at startup
  4. the environment variables is four kilobytes.
26
Q

Lambda@Edge

A

you deploy Lambda functions, not in a specific region, but alongside each region around the world
with your CloudFront CDN.

27
Q

Lambda@Edge Example

A

we can create a global application, for example.

So, our website will be statically hosted onto Amazon S3 in the HTML form, then the user will visit it and will be asked, with some client side JavaScript to do
some API requests to CloudFront and CloudFront will be triggering our Lambda@Edge function

which is globally and running globally alongside your edge locations,

and then your Lambda function may be querying
data in Amazon, DynamoDB

28
Q

four types of Lambda functions at the edge

A

we have our user, talking to your CloudFront edge locations that are going to be talking to your origin.

  1. we can change the viewer requests. So the viewer request is when CloudFront receives a request from a viewer, so from a user, we can modify that request.
  2. we can modify the origin request, and this request is before CloudFront forwards the request
    to the origin.
  3. we can modify the third request, which is the origin response, which is done when CloudFront received the response from the origin
  4. we can modify the viewer response, which is before CloudFront forwards the response to the viewer.

we can generate responses to viewers, without ever sending any request to the origin, by just using the viewer request, and the viewer response Lambda functions.

29
Q

Lambda@Edge Use Cases

A
  1. Website Security and Privacy
  2. Dynamic Web Application at the edge
  3. Search Engine Optimization
  4. Intelligently route across origins and data centers
  5. Bot mitigation at the Edge
  6. Real-time image transformation
  7. A/B Testing
  8. User Authentication and Authorization
  9. User Prioritization
  10. User Tracking and Analytics
30
Q

You have a Lambda function that will process data for 25 minutes before successfully completing. The code is working fine in your machine, but in AWS Lambda it just fails with a “timeout” issue after 3 seconds. What should you do?

A

run your code somewhere else than Lambda - the max timeout is 15 minutes

31
Q

You’d like to have a dynamic DB_URL variable loaded in your Lambda code

A

place it in the environment variables

Environment variables allow for your Lambda to have dynamic variables from within

32
Q

A DynamoDB table has been provisioned with 10 RCU and 10 WCU. You would like to increase the RCU to sustain more read traffic. What is true about RCU and WCU?

A

RCU and WCU are decoupled, so WCU can stay the same

33
Q

You are about to enter the Christmas sale and you know a few items in your website are very popular and will be read often. Last year you had a ProvisionedThroughputExceededException. What should you do this year?

A

create a DAX cluster

A DynamoDB Accelerator (DAX) cluster is a cache that fronts your DynamoDB tables and caches the most frequently read values.

They help offload the heavy reads on hot keys off of DynamoDB itself, hence preventing the ProvisionedThroughputExceededException

34
Q

You would like to automate sending welcome emails to the users who subscribe to the Users table in DynamoDB. How can you achieve that?

A

enable DynamoDB Streams and have the Lambda function receive the events in real time