首页 > 解决方案 > AWS lambda 与 AWS CLI

问题描述

我想知道这两种技术中哪个是更好的选择:

我更喜欢在 AWS Lambda 中编写代码,但我想知道使用 Lambda 是否有任何特定优势。

PS:我必须执行的那些功能几乎相同(它们使用相同的算法),因此功能上没有区别。

问候

标签: aws-lambdaaws-cli

解决方案


I understand that you would like to know if there is any particular advantage of using AWS Lambda instead of using EC2 Instances.

Here are some advantages of AWS Lambda:

  • Reduced cost. Lambda follows a pay-as-you-invoke pricing model, unlike AWS EC2, and the first million invokes fall under the free tier category[1]. Depending on your use case, you might be able to save a lot using AWS Lambda on your production environment.

  • No system administration payload. AWS Lambda follows serverless computing paradigms, and there's no need to start servers, configure them as per your need, and maintain them.

  • An AWS Lambda function can be pretty convenient for automation tasks and can be triggered by a number of services[2]. Eg: If you upload a file to an AWS S3 bucket, you could choose to trigger a Lambda function that compresses the file and stores it in another S3 bucket.

However, Lambda has some disadvantages as well, compared to EC2/ECS:

  • Lambda functions are prone to the Cold Start issue. A Cold Start issue usually occurs when a Lambda function hasn't been invoked for quite some time. AWS deploys a new container to the Lambda function in the backend, and there might be delayed invocations at times[3].

  • It can get arduous to debug AWS Lambda function logs and metrics in Amazon CloudWatch.

  • A Lambda function has a supported maximum execution time of 15 minutes, and there is a time period limitation. Therefore, it might not be possible to use a Lambda function for time-consuming operations(eg: Processing large flat files).

Amazon EC2 has a system administration payload and it might cost a bit higher, but there are no Lambda Cold Start issues, and it can even work for long running tasks. Therefore, you could choose to use EC2 or Lambda depending on your exact use-case.

I hope this answer helps you out.

References

[1]. https://aws.amazon.com/lambda/pricing/

[2]. https://docs.aws.amazon.com/lambda/latest/dg/invoking-lambda-function.html

[3]. https://docs.aws.amazon.com/lambda/latest/dg/running-lambda-code.html


推荐阅读