Certopolis

AWS Certified Developer – Associate

Lambda SnapStart vs provisioned concurrency (DVA-C03)

According to the Lambda Developer Guide, SnapStart initializes a function when you publish a version, snapshots that environment and resumes new environments from the snapshot, with startup as low as sub-second. Provisioned concurrency keeps environments initialized and ready to respond in double-digit milliseconds, for an extra charge. SnapStart does not support provisioned concurrency.

How does SnapStart work?

With SnapStart, Lambda runs your initialization code when you publish a function version. It takes a Firecracker microVM snapshot of the memory and disk state of the initialized execution environment, encrypts it and caches it. New execution environments are then resumed from the snapshot instead of being initialized from scratch.

SnapStart works only on published versions and on aliases that point to versions, not on $LATEST. It supports the Java 11 and later, Python 3.12 and later and .NET 8 and later managed runtimes. Other managed runtimes and OS-only runtimes are not supported. It does not support provisioned concurrency, Amazon EFS or ephemeral storage above 512 MB.

For Java managed runtimes there is no additional cost. For the other runtimes you pay to cache each published version's snapshot and pay a restoration charge each time an environment is restored. AWS notes that SnapStart works best for functions invoked at scale.

What changes when code resumes from a snapshot?

One snapshot is the starting state for many execution environments. Unique IDs, secrets or random seeds created during initialization would be shared, so generate them after initialization. Every environment also returns the same hostname.

The state of network connections opened during initialization is not guaranteed after a restore. Connections made by an AWS SDK usually resume on their own. For others, such as a database connection, re-establish them in the handler or in an after-restore runtime hook. Avoid binding connections to fixed source ports.

Runtime hooks run code before the snapshot is taken or after a restore. In Python the Snapshot Restore for Python library provides @register_before_snapshot and @register_after_restore. A before-snapshot hook suits heavy work such as downloading files or loading models: a file it writes to /tmp is part of the snapshot. After-restore hooks must finish within 10 seconds or Lambda raises SnapStartTimeoutException.

When is provisioned concurrency the answer?

Provisioned concurrency is a number of pre-initialized execution environments allocated to a function version or alias. They respond immediately, and the feature is designed for double-digit millisecond response times. AWS says to use it when cold start requirements are too strict for SnapStart.

It cannot be used with $LATEST, and the event source must point at the alias or version that has it. It adds charges, while reserved concurrency does not. Reserved concurrency sets the maximum and minimum number of concurrent instances for a function, and provisioned concurrency on a function cannot exceed its reserved concurrency.

Example: a Java checkout function with a known peak of 400 concurrent requests that must all start in double-digit milliseconds needs 400 units of provisioned concurrency on the alias the API calls. SnapStart brings startup to as low as sub-second, which does not meet a double-digit millisecond requirement.

Where the exam catches people

  • Believing SnapStart can be used on $LATEST: it works only on published versions and aliases that point to them.
  • Believing SnapStart and provisioned concurrency can be combined: SnapStart does not support provisioned concurrency.
  • Believing a database connection opened during initialization is still good after a restore: its state is not guaranteed. Reconnect in the handler or in an after-restore hook.
  • Believing a large download belongs in an after-restore hook: after-restore hooks have 10 seconds. A before-snapshot hook does the work once and the result is in the snapshot.
  • Believing reserved concurrency removes cold starts: it reserves and caps capacity. Provisioned concurrency is the setting that pre-initializes environments.

Written from these sources

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. A Java AWS Lambda function has Lambda SnapStart turned on. Its static initializer opens a JDBC connection to an Amazon RDS for PostgreSQL database, and the handler runs every query on that connection. Queries that run soon after an execution environment resumes from the snapshot sometimes fail because the connection is broken. SnapStart must stay on, and every query must run on a working connection. Which solutions will meet these requirements? (Select TWO.)

    Right. In the game that’s Renown for your Troubleshooting and Optimization building.

    Not that one: A,E is right. In the game your Troubleshooting and Optimization building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Connections that an AWS SDK opens normally resume on their own, but a JDBC connection does not, so it must be re-established after the restore. Lambda recommends doing that in the function handler, or alternatively in an after-restore runtime hook. Checking the connection before each query in the handler and reopening it when it is broken meets the requirement, and so does an after-restore hook that replaces the connection before the handler runs.

    Written from docs.aws.amazon.com/lambda/latest/dg/snapstart-best-practices.html

  2. A Python 3.13 AWS Lambda function in handler.py uses SnapStart on published versions behind an alias. On the first call in each execution environment, the handler downloads a 300 MB model file from Amazon S3 to /tmp, so the first request after every restore is slow. The team's unit tests import handler.py, so importing it must not start the download. Restored execution environments must already hold the file in /tmp. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Troubleshooting and Optimization building.

    Not that one: B is right. In the game your Troubleshooting and Optimization building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The Snapshot Restore for Python library provides two decorators: @register_before_snapshot for functions to run before Lambda creates the snapshot, and @register_after_restore for functions to run when Lambda resumes from it. A before-snapshot hook that writes the model to /tmp runs once, at publish time, and the file is part of the snapshot every restored environment starts from; the SnapStart best-practices page recommends this hook for downloading external files. The decorator only registers the function at import, so the unit tests do not trigger the download.

    Written from docs.aws.amazon.com/lambda/latest/dg/snapstart-runtime-hooks-python.html

  3. A Java 21 AWS Lambda function backs a checkout API. During each flash sale, traffic climbs within seconds to a known peak of 400 concurrent requests. Every request in that peak, including the first request served by each execution environment, must start running handler code within double-digit milliseconds. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Troubleshooting and Optimization building.

    Not that one: D is right. In the game your Troubleshooting and Optimization building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Configuring 400 units on the alias the API calls covers the whole known peak, so even the first request on each environment finds it already initialized. Provisioned concurrency is configured on a published version or an alias, which is why a version and an alias come first.

    Written from docs.aws.amazon.com/lambda/latest/dg/snapstart.html

Ask for something