官术网_书友最值得收藏!

Pricing and limitations

As discussed sometime earlier in this chapter, a Lambda function's cost depends on the amount of compute resources (RAM) supplied to it, as well as the duration of the function's execution. But that's not all! A Lambda function is even billed based on the total number of requests collectively across all your functions. The cost is calculated each time Lambda responds to a request generated either by an event or by a manual invocation. This also includes responses triggered during testing of your Lambda function using the Amazon Management Console. At the time of writing, AWS charges $0.20 per 1 million requests ($0.0000002 per request). The best part is that, each month, you get one million requests and 400,000 GB of compute time for free. This feature does not expire, even after your Free Tier validity is over.

Let's take a simple example to understand this better. Consider your Lambda function has been allocated the minimal 128 MB of RAM and it will execute a good 5 million times in one month for one second each. In that case, the cost is calculated as follows:

  1. First, we calculate the monthly compute charge. The monthly compute price is $0.00001667 per GB and the Free Tier provides 400,000 GB for free each month:
  1. Similarly, we now calculate the monthly request charge. The monthly request price is $0.20 per 1 million requests and the Free Tier provides 1 million requests per month:
  1. So, your total cost for running a Lambda function with 128 MB of RAM for a duration of 1 second a million times is >> Monthly Compute Charges (a) + Monthly Request Charge (b) = $3.75 + $0.8 = $4.55.
  2. Not impressed? Let's take a look at how a Lambda function fares with an EC2 instance when it comes to pricing with a simple example.
  3. Consider a really simple Lambda function that will execute roughly 300,000 requests in one month with 3 seconds for each. We will give our function a good 512 MB of RAM for execution. The monthly compute charge is calculated as follows:
  1. Similarly, we calculate the monthly request charge as follows:
    • The monthly request price is $0.20 per 1 million requests and the Free Tier provides 1 million requests per month: 
    • Since the number of requests is less than that given in Free Tier, the monthly request charge (b) evaluates to $0:

Compare that with an EC2 t2.nano (512 MB) instance, running 24/7 for a full month, amounts to $4.32! Now that's really cheap!

Let's also check out some common Lambda limitations as well. For starters, Lambda is not designed for applications that have a long execution time. The maximum execution time supported for a Lambda function is 300 seconds. There are also some hard limits on the amount of RAM you can assign to your Lambda functions. The minimum is 128 MB and it goes all the way up to 1536 MB in increments of 128. Each Lambda function also receives 500 MB of non-persistent scratch space that is generally mounted to /tmp.

If you are looking for persistent storage options, you may want to leverage S3, RDS, or DynamoDB for the same.

There are also some limitations set on the size of the code that you can upload to Lambda. Each Lambda function supports a max upload of 50 MB of code, bundled either as a .zip or  .jar file. You can read more about the various limits set on Lambda code deployments, as well as executions here: http://docs.aws.amazon.com/lambda/latest/dg/limits.html.

Besides these limits, you should also know that, at the time of writing this book, AWS Lambda only supports Java, Node.js, Python, and C# as programming languages. There are ways in which you can even execute other non-supported languages and codes, such a, PHP, Go, and Ruby, but that is out of the scope of this book, as we will be primarily concentrating on development using Node.js itself. You can still get a good hands-on feel for the other non-supported scripting languages on Lambda by looking at https://aws.amazon.com/blogs/compute/scripting-languages-for-aws-lambda-running-php-ruby-and-go/.

主站蜘蛛池模板: 泰安市| 河曲县| 灯塔市| 仲巴县| 司法| 台东县| 石渠县| 定结县| 都匀市| 永福县| 广昌县| 铁岭市| 五大连池市| 吴旗县| 尼木县| 合川市| 郓城县| 阿尔山市| 克东县| 同德县| 开封市| 和田市| 双牌县| 定边县| 东阳市| 正镶白旗| 吉首市| 凭祥市| 东台市| 潢川县| 胶州市| 屏山县| 社会| 遂川县| 扶绥县| 天等县| 仪陇县| 巧家县| 洪江市| 平阴县| 荣成市|