Lesson 2 of 3 AWS Lambda for Data Engineering

Working Within Lambda Limits and Controlling Concurrency

This lesson explains Lambda's limits, which decide which data jobs it can run at all, and its concurrency settings, which decide how hard it drives the systems behind it.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the Lambda limits that affect data processing.
  • Calculate concurrency from request rate and duration.
  • Use reserved and provisioned concurrency.
  • Protect downstream systems from Lambda scaling.

Key limits

Lambda's limits decide which data tasks it can do. Memory ranges from 128 MB to 10 GB, and CPU power grows in proportion, so a slow, CPU-bound function often runs faster, and sometimes cheaper, with more memory. A function can run for at most 15 minutes, so longer processing belongs in Glue, EMR, ECS or a Step Functions workflow that splits the work. Payloads are limited to 6 MB for synchronous calls and 1 MB for asynchronous calls, so large data is passed as a reference to an S3 object, not in the event. The following table summarises the limits.

SettingRange
Memory128 MB to 10 GB; CPU scales with memory
TimeoutAt most 15 minutes (longer jobs belong in Glue, EMR, ECS or Step Functions)
Synchronous payload6 MB request and response
Asynchronous payload1 MB

15min

Maximum function run time

10GB

Maximum memory

6MB

Synchronous payload

1MB

Asynchronous payload

Scenario questions

Within Lambda's limits?

Exam skills 1.4.2

Decide what to do when a task meets Lambda's limits.

Log in to try this activity Interactive activities are free with an account.

How Lambda scales

Each execution environment handles one request at a time, so concurrency equals requests per second multiplied by average duration. Each function scales by up to 1,000 additional environments every ten seconds, within the account's Regional concurrency quota (1,000 by default, which can be raised). For stream sources, concurrency follows the number of shards multiplied by the parallelisation factor.

Fill in the value

Concurrency arithmetic

Exam skills 1.4.2

Work out how much concurrency a workload needs.

Log in to try this activity Interactive activities are free with an account.

Concurrency controls

Concurrency is the number of function instances running at once, and three settings control it. Reserved concurrency sets aside capacity for a function and also caps it at that number. The cap is often the main point in pipelines: it stops a burst of events from opening thousands of connections to a database that cannot handle them. Provisioned concurrency keeps a number of execution environments initialised and ready, which removes the start-up delay, the cold start, for latency-sensitive functions.

Maximum concurrency on an SQS event source limits how many functions one queue invokes at the same time, so several queues can share a function without one consuming all of its capacity. The following table summarises the controls.

SettingEffect
Reserved concurrencyGuarantees capacity and caps it, protecting downstream systems such as a database
Provisioned concurrencyKeeps environments initialised, removing cold starts
Maximum concurrency on an SQS event sourceLimits how many functions a queue invokes at once
Match the pairs

Concurrency controls

Exam skills 1.4.2

Match each requirement with the concurrency control.

Log in to try this activity Interactive activities are free with an account.

Protecting downstream systems

Lambda can scale much faster than the databases and APIs it calls: a burst of events can start hundreds of concurrent invocations, each opening a database connection or calling an API with a rate limit. Several protections prevent this from overwhelming downstream systems.

Reserved concurrency caps how many copies of a function can run at once, and for SQS event sources, maximum concurrency caps how many concurrent invocations the queue triggers. RDS Proxy pools database connections, so many invocations share a small number of connections. An Amazon SQS queue placed in front of the function turns bursts into a steady flow that downstream systems can handle.

The following diagram compares an unprotected function with a protected one.

Protecting a database from a burst of events. Without controls, hundreds of concurrent invocations each open a connection and overwhelm the database. With an SQS queue in front, a maximum concurrency on the event source and RDS Proxy pooling connections, the burst becomes a steady flow the database can handle.
The numbers are illustrative.
Worked example

Is Lambda the right tool?

Lambda is well suited to some data processing jobs but not to others. The following table assesses several jobs against Lambda's limits and gives the reason in each case.

JobFits Lambda?Reason
Validate and route each uploaded file (under 1 minute each)YesShort, event-driven, scales with uploads
Transform a 30 GB fileNo15-minute limit and 10 GB memory; use Glue or EMR
Process records from a Kinesis streamYesEvent source mapping handles batching
Join two large tables every nightNoA distributed engine (Glue, EMR, Redshift) suits it

When a Lambda-based pipeline writes to a database, reserved concurrency or the SQS event source's maximum concurrency stops thousands of parallel functions overwhelming it.

Check yourself

How can a database be protected from Lambda's fast scaling?

Show answer

With reserved concurrency, which caps the function's concurrent executions, and RDS Proxy, which pools connections.

Exam Tips

Remember for the exam

  • Jobs longer than 15 minutes belong in Glue, EMR, ECS or Step Functions.
  • To give a CPU-bound function more CPU, increase its memory.
  • To protect a database from Lambda's scaling, use reserved concurrency and RDS Proxy.
  • To remove cold starts, use provisioned concurrency.
  • To limit how fast a queue drives a function, set maximum concurrency on the SQS event source.