服务 · 无服务器
AWS Lambda
Runs your code in response to events, with no servers to manage.
本课尚未翻译,暂以英文显示。
- 1An event arrives: a file lands in S3, a request comes through API Gateway, or an EventBridge rule fires.
- 2Lambda runs your function, which here saves the result in Amazon DynamoDB.
分步说明
- 1An event arrives: a file lands in S3, a request comes through API Gateway, or an EventBridge rule fires.
- 2Lambda runs your function, which here saves the result in Amazon DynamoDB.
You deploy
- Lambda
- A function: your code
- Fargate
- A container image
- EC2
- A server built from an AMI
You manage
- Lambda
- Your code and its settings
- Fargate
- Your containers and their settings
- EC2
- The operating system and everything on it
You pay for
- Lambda
- Requests and run time
- Fargate
- CPU and memory while tasks run
- EC2
- Instances while they run
One run can last
- Lambda
- Up to 15 minutes, by default
- Fargate
- As long as needed
- EC2
- As long as needed
| 比较项 | Lambda | Fargate | EC2 |
|---|---|---|---|
| You deploy | A function: your code | A container image | A server built from an AMI |
| You manage | Your code and its settings | Your containers and their settings | The operating system and everything on it |
| You pay for | Requests and run time | CPU and memory while tasks run | Instances while they run |
| One run can last | Up to 15 minutes, by default | As long as needed | As long as needed |
1 / 2
You deploy
- Lambda
- A function: your code
- Fargate
- A container image
- EC2
- A server built from an AMI
You manage
- Lambda
- Your code and its settings
- Fargate
- Your containers and their settings
- EC2
- The operating system and everything on it
| 比较项 | Lambda | Fargate | EC2 |
|---|---|---|---|
| You deploy | A function: your code | A container image | A server built from an AMI |
| You manage | Your code and its settings | Your containers and their settings | The operating system and everything on it |
2 / 2
You pay for
- Lambda
- Requests and run time
- Fargate
- CPU and memory while tasks run
- EC2
- Instances while they run
One run can last
- Lambda
- Up to 15 minutes, by default
- Fargate
- As long as needed
- EC2
- As long as needed
| 比较项 | Lambda | Fargate | EC2 |
|---|---|---|---|
| You pay for | Requests and run time | CPU and memory while tasks run | Instances while they run |
| One run can last | Up to 15 minutes, by default | As long as needed | As long as needed |
是什么
AWS Lambda runs your code without you provisioning or managing servers. You upload a function, connect it to a trigger, and Lambda runs it each time the event happens. AWS handles the servers, the operating system, scaling and patching. AWS now calls this kind of function a Lambda Event Function, to tell it apart from newer Lambda options.
是什么
Many AWS services can trigger a function. A new file in Amazon Simple Storage Service (Amazon S3) or a request through Amazon API Gateway can start it. So can a message in an Amazon Simple Queue Service (Amazon SQS) queue, or a rule or schedule in Amazon EventBridge. Lambda scales automatically, from a few events a day to heavy traffic.
You pay for the number of requests and the time your code runs, not for idle time. By default, one run can last up to 15 minutes. Longer jobs fit better on AWS Fargate, AWS Batch or Amazon Elastic Compute Cloud (Amazon EC2).
要记住
- Event-driven: code runs when something happens.
- No servers to provision, patch or scale.
- Pay per request and for run time, not for idle time.
- One run lasts up to 15 minutes by default.
- You manage your code, its permissions and your data. AWS runs everything under it.
考试中
- “Run code in response to events without provisioning or managing servers” points to AWS Lambda.
- “A job that runs for several hours” does not fit Lambda. Look at AWS Batch, AWS Fargate or Amazon EC2.
别和这些弄混
AWS FargateServerless compute for containers: no servers or clusters of instances to manage.
Amazon Elastic Compute Cloud (Amazon EC2)Virtual servers in the cloud that you launch in minutes and fully control.
AWS BatchPlans, schedules and runs large numbers of batch jobs, and provides the compute they need.