All technological notes.
AWS LambdaEC2 vs Lambda
EC2:
Lambda
sample:
SQS allows you to retain messages for days and process them later, while we can take down our EC2 instances.Easy Pricing:
CloudWatchLambda language support
container image must implement the Lambda Runtime API必须, 否则选择 ECS/FargateECS / Fargate is preferred for running arbitrary Docker images
You can find overall pricing information here:
Pay per calls :
Pay per duration: (in increment of 1 ms )
It is usually very cheap to run AWS Lambda so it’s very popular

Execution:
/tmp): 512 MB to 10GBDeployment:
/tmp directory to load other files at startupSample:
Sample:


Many modern applications execute some form of the logic at the edge
Edge Function:
CloudFront distributionsCloudFront provides two types:
CloudFront FunctionsLambda@EdgeBenefits:
CloudFront FunctionsFeatures:
JavaScriptCDN customizationsNative feature of CloudFront (manage code entirely within CloudFront)
Used to change Viewer requests and responses:
Viewer Request: after CloudFront receives a request from a viewerViewer Response: before CloudFront forwards the response to the viewer
Lambda@EdgeNodeJS or PythonScales to 1000s of requests/second
Author your functions in one AWS Region (us-east-1), then CloudFront replicates to its locations
Used to change CloudFront requests and responses:
Viewer Request
Origin Request
Origin Response
Viewer Response

CloudFront Functions vs. Lambda@Edge| CloudFront Functions | Lambda@Edge | |
|---|---|---|
| Runtime Support | JavaScript |
Node.js, Python |
| # of Requests | Millions of requests per second | Thousands of requests per second |
| CloudFront Triggers | Viewer Request/Response | Viewer Request/Response + Origin Request/Response |
| Max. Execution Time | < 1 ms | 5 – 10 seconds |
| Max. Memory | 2 MB | 128 MB up to 10 GB |
| Total Package Size | 10 KB | 1 MB – 50 MB |
| Network Access, File System Access | No | Yes |
| Access to the Request Body | No | Yes |
| Pricing Free tier available, 1/6th price of @Edge | No free tier, charged per request & duration |
Use Cases
CloudFront Functions
Lambda@Edge
By Default
VPC (in an AWS-owned VPC)
VPC
VPC ID,SubnetsSecurity GroupsLambda will create an ENI (Elastic Network Interface) in your subnets

If Lambda functions directly access your database, they may open too many connections under high load
RDS Proxy benefits:
IAM authentication and storing credentials in Secrets ManagerThe Lambda function must be deployed in your VPC, because RDS Proxy is never publicly accessible

Goal
Lambda functions from within your DB instanceSupported for RDS for PostgreSQL and Aurora MySQL
Must:
Lambda function from within your DB instance (Public, NAT GW, VPC Endpoints)Lambda function (Lambda Resource-based Policy & IAM Policy)
RDS Event NotificationsDB instance itself (created, stopped, start, …)只是关于数据库实例的信息SNS or subscribe to events using EventBridge


















