← AWS SAA

Note for AWS Serverless

awscloudserverless

Serverless in AWS

Lambda
DynamoDB
S3
SNS & SQS
Aurora Serverless
Kinesis Data Firehose
API Gateway
Fargate
Cognito
Step functions

Lambda

Overview

Virtual Functions
Can run up to 15 mins (short execution)
Run on-demand
Automatic Scaling
Lambda will be hosted on AWS owned VPC by default.

Lambda Benefits

Pricing

pay per request and compute time
Can user various Programming languages
Can get RAM up to 10GB
Increasing RAM also improve CPU and network

Lambda container images

Lambda support container images but the container must installed Lambda Runtime API
But ECS/Fargate is preferred for container runtime APIs.

Lambda Integration

Main one
API Gateway
Kinesis (for data transformation on the fly)
S3
DynamoDB
Cloudfront (lambda at edge)
Cloudwatch Event bridge
Cloudwatch logs
SNS
SQS
Cognito(for authentication)

Usages Example
Thumbnail creation
Serverless cronjob

Limitations

Time - up to 15 mins
RAM - 128MB to 10GB
ENV- 4KB
Disk Capacity- 512MB to 10GB
Concurrency - 1000 (can be increased)
Compressed size - 50 MB
Uncompressed - 250 MB

Concurrency

Scale up to 1000 but should properly limit
which is called reserve concurrency
Each invocation exceeded to the limit will trigger throttle
Throttle
Sync ->return throttle error 429.
Async -> retry automatically and then go to DLQ

NOTE : Lambda function scaling limit applies to all the function in my account(means if multiple services using lambda but one hits the limit. The other won't be able to scale too)

Cold start
can probably take a long time based on the init load
can be solve that cold start by provisioned concurrency.
Concurrency is allocated before the function is invoked.
Application Auto Scaling can manage the concurrency. (schedule or target utilization)

SnapStart

To reduce the initial load time.
When published a new lambda function, it will run first then take a snapshot of both memory and disk state. Which can be reused to invoke lambda function and will reduce the load time.
Snapshot is cached for low latency access

CloudFront function and lambda@edge

Cloudfront function (Written in JS)

Shorter Execution time
To manipulate the viewer request and response

Lambda@edge(python and Nodejs)

Longer Execution time
Can manipulate

  1. Viewer Request
  2. Origin Request
  3. Origin Response
  4. Viewer Response

Best Practice

With RDB user RDB proxy to reduce load on rdb by lambda functions.
Invoke Lambda from RDS.
RDS-> event-> lambda -> invoke other function
(lambda won't get any data information. Just get the event)