35

I'm trying to find the maximum number of virtual processor cores available in AWS Lambda. The official documentation implies that it scales with the amount of configured memory:

In the AWS Lambda resource model, you choose the amount of memory you want for your function, and are allocated proportional CPU power and other resources. For example, choosing 256MB of memory allocates approximately twice as much CPU power to your Lambda function as requesting 128MB of memory and half as much CPU power as choosing 512MB of memory.

However, running the following snippet gets me Number of cores = 2 even if I configure the highest amount of memory requestable: 1536 MB.

package example;

import java.io.{ InputStream, OutputStream }

class Main {
  def main(input: InputStream, output: OutputStream): Unit = {   
    val result = "Number of cores = " + Runtime.getRuntime().availableProcessors()
    output.write(result.getBytes("UTF-8"))
  }
}

So what's going on here? Am I using availableProcessors() wrong or misinterpreting its result incorrectly? Or are there some other configurations that's need to get more cores?

1
  • 3
    You may also be misinterpreting the faq... remembering that everything's virtualized, the phrase "proportional CPU power" could also refer to the proportion of available CPU cycles allocated to a job by the hypervisor (if you're allowed, e.g., 25%, the hypervisor will "steal" the other ~75%), rather than scaling of the number of cores. Dec 7, 2015 at 17:03

4 Answers 4

27
+200

As per AWS Lambda documentation and forum, AWS doesn't state which instance types that AWS uses for this service. In the end of 2014, AWS used compute-optimize-like instances. And now, AWS uses general-purposes-like instances.

The CPU share dedicated to a function is based off of the fraction of its allocated memory, per each of the two cores. For example, an instance with ~ 3 GB memory available for lambda functions where each function can have up to 1 GB memory means at most you can utilize ~ 1/3 * 2 cores = 2/3 of the CPU. The details may be revisited in the future, but that is the fractional nature of our usage model.

You can only utilize the CPU power proportional to the memory. Although, the lower and higher memory are in a same instance, they will share proportional CPU power, which is the higher memory will get more CPU power. If you read your total CPU cores is 2, it doesn't mean that you can fully utilize all of the CPU.

Currently, there is no way to configure CPU. Only total memory that you can adjust.

3
  • Can you share where you found that they use general-purpose like instances for Lambda? I can't find it at all.
    – stephenbez
    Oct 24, 2017 at 20:56
  • 1
    The documentation was changed. At that time, the documentation was: web.archive.org/web/20150905231931/http://docs.aws.amazon.com/… Oct 28, 2017 at 14:28
  • 1
    Just for clarifity: you get 2 - 6 vCPUs, which equals your logical cores (reported in code). But you are right, their capabilities change proportional to your requested memory - so you can configure your CPU indirectly, which is exactly what's best practice. Be aware that from 3009 MB RAM, your two vCPUs will stop scaling vertically and multi-process code is needed to continue scaling (horizontally). Currently, Intel(R) Xeon(R) Processors @ 2.50GHz are used but configuration changes.
    – Cadoiz
    Sep 16, 2021 at 8:23
22

Edit 16 Sep 2021

This answer is almost 6 years old and not really relevant anymore. See comments, you can now select up to 6 cores based on the amount of RAM you select.

Original answer

You're asking the wrong question I think (or want to use Lambda for something where it's not built for). One Lambda function has only one or two cores available, however, the power in Lambda is that you can run hundreds of them at the same time. The default limit of the amount of active Lambda functions is 100, but this is just a limit to safeguard the infrastructure (and your wallet). You can ask for more.

So your account can have 100 Lambda functions running at the same time, which you could see as 100 cores (however it's not). If you request a limit increase, this could also be 1000 or 10,000 or 100,000.

Analogy: instead of having 1 100-core computer, you have 100 1-core computers.

4
  • 5
    That can be a totally valid question for certain use-cases – for instance, processing files from an S3 bucket using parallel processing ;) Aug 28, 2018 at 23:00
  • 2
    limit is 1000 now :-)
    – Alex B
    Jul 18, 2021 at 18:58
  • 3
    Also the info is deprecated now, as you will always get 2 < n < 6 cores. Today is 2021-09-16, mind that this is probably going to change again.
    – Cadoiz
    Sep 16, 2021 at 8:28
  • You are correct, this answer is ancient and not relevant anymore. I updated the answer so others will see Sep 16, 2021 at 13:53
21

While AWS till today didn't disclose any details regarding processing power of AWS Lambda functions, they now did after announcing an increase of the maximum memory from 1536 MB to 3008 MB. Their documentation now states:

Functions larger than 1536MB are allocated multiple CPU threads, and multi-threaded or multi-process code is needed to take advantage of the additional performance.

Based on that, we can conclude that all AWS Lambda functions up to 1536 MB of memory have a single virtual processor core available, while functions with more memory have two cores available.

Update:

While that part of the documentation isn't available anymore, Chris Munns from AWS recently at the AWS Serverless Startup Day on 2018-07-10 disclosed that all AWS Lambda functions with more than 1.8GB of memory are running on multiple cores. So apparently the boundary between single-core and multi-core for AWS Lambda functions moved from 1.5GB to 1.8GB.

4
  • "Their documentation now states: ..." Except that it no longer does.
    – Phil
    Jan 22, 2018 at 23:08
  • It is not stated in the docs anymore. I wonder if it is still true. Feb 7, 2018 at 15:34
  • 2
    Afaik it is still true. Also these benchmarks from the end of January still suggest it: engineering.opsgenie.com/… It's really a shame that AWS removed it from the docs.
    – Dunedan
    Feb 8, 2018 at 6:44
  • That info is deprecated now you will always get 2 < n < 6 cores as of 2021-09-16. The memory can be configured ranging from 128 MB to 10 GB. Plus the documentation link seems to work again.
    – Cadoiz
    Sep 16, 2021 at 8:27
10

According to the latest announcement from AWS, the maximum number of vCPUs is six.

1
  • 1
    Updated URL (change: no trailing 0)
    – learner
    Oct 5, 2021 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.