0%
AWS Developer Associate (DVA-C03) Exam Prep: Development, Security, Testing, Deployment and Troubleshooting
How the Exam Works
Domain 2: Security
Domain 3: Testing and Deployment
Domain 4: Troubleshooting and Optimization
New in DVA-C03: Containers and AI
Final Review and Mock Exams
Lambda Development
Lambda is the centre of the development domain, and the exam expects you to know it from the inside: what your handler receives, what runs once and what runs every time, how memory and CPU relate, and what you can and cannot rely on between invocations. This section covers the handler and the execution environment. Later sections cover invocation types, error handling, concurrency and versions, and packaging. Event driven patterns with SQS, SNS, EventBridge and Kinesis get their own lesson; here we treat them only as sources that invoke a function.
The handler
A Lambda function is code plus configuration. The code exposes a handler, a function that Lambda calls with two arguments: the event and the context. The event is the input, a JSON document whose shape depends on the source. An API Gateway proxy event has a path, headers, query string parameters and a body. An S3 event has a list of records with bucket names and object keys. An SQS event has a list of messages. The context object carries information about the invocation: the request ID, the function name and version, the memory limit and a method that returns the remaining time before the timeout.
The handler setting in the function configuration names the file and the function, such as app.handler. A wrong handler setting is a classic deployment bug: the function fails on every call with an error saying the handler cannot be found, even though the code is fine. In Node.js the handler is usually an async function that returns a value or throws; in Java it is a class implementing a handler interface. The exam does not depend on the language, but it does expect you to know that the handler is the entry point and that its name is configuration.
The execution environment
Each invocation runs inside an execution environment: a lightweight micro virtual machine with the runtime, your code, any layers and a small writable disk. Lambda creates an environment when it needs one, keeps it for a while after an invocation finishes, and reuses it for later invocations of the same function version. One environment handles one invocation at a time. If ten requests arrive at once, Lambda needs ten environments.
The lifecycle has three phases. In the init phase Lambda downloads your code, starts the runtime, runs extensions and then runs your initialization code, which is everything outside the handler: imports, SDK clients, configuration loading, database connection pools. In the invoke phase Lambda calls the handler. In the shutdown phase, which happens when Lambda decides to retire the environment, extensions get a short time to clean up. Lambda limits how long init may take, roughly ten seconds for on-demand functions, so very heavy startup work belongs in the handler or in a lazy loader.
Cold starts
A cold start is an invocation that has to wait for a new environment to be created and initialized. A warm start reuses an existing environment and runs only the handler. Cold starts happen on the first call after a deployment, when traffic rises faster than existing environments can absorb, and after an environment has been idle long enough to be retired. Their cost depends on the runtime, the package size and how much init code you run. Interpreted runtimes with small packages often start in a few hundred milliseconds; large Java functions with heavy frameworks can take several seconds.
You can reduce cold start cost in several ways. Keep the deployment package small and import only what you use. Create SDK clients and connections outside the handler so warm calls reuse them. Choose more memory, which also gives more CPU, so init runs faster. For Java, Python and .NET, enable SnapStart, which runs init once when you publish a version, takes a snapshot of the initialized environment and restores from the snapshot instead of running init again. For latency sensitive paths where you cannot accept any cold start, use provisioned concurrency, covered in section four.
A common exam distractor is to keep a function warm with a scheduled ping every few minutes. It is an old trick, it only keeps one environment warm, and it does nothing when traffic needs more environments than you pinged. Provisioned concurrency is the supported answer.
What survives between invocations
Because environments are reused, anything initialized outside the handler persists across warm invocations: global variables, open connections, cached configuration and files written to /tmp. This is a feature. Reusing an SDK client avoids a fresh TLS handshake on every call, and caching a secret for a few minutes avoids a Secrets Manager call per request.
It is also a trap. Lambda never guarantees reuse. An environment may be retired at any time, and concurrent requests land in different environments with different global state. So never store anything in memory or /tmp that must survive, such as a counter, a session or a queue of work. Use DynamoDB, S3 or ElastiCache for state. And be careful with mutable globals: a global list that you append to on every request grows without bound on a warm environment and leaks data between callers.
Memory, CPU and the writable disk
You set memory from 128 MB up to 10,240 MB. Lambda allocates CPU in proportion to memory: at around 1,769 MB a function has the equivalent of one full vCPU, and at the top of the range it can use up to six. There is no separate CPU setting. So a CPU bound function that is slow at 512 MB can become faster and sometimes cheaper at a larger size, because billing is per millisecond of duration times memory. Tools that run your function at several memory sizes and compare cost and duration help you find the sweet spot.
Each environment has a writable /tmp directory. Its default size is 512 MB and you can configure it up to 10,240 MB. It is useful for unpacking archives, staging files for a multipart upload or caching a model file across warm invocations. It is not shared between environments and disappears when the environment is retired.
Environment variables
Environment variables hold configuration that changes between stages, such as table names, queue URLs and feature flags. Read them at init, not on every call. The total size of all variables is limited to 4 KB. Lambda encrypts them at rest using an AWS managed KMS key by default, and you can choose a customer managed key. The console also offers encryption helpers that encrypt a value client side so it appears encrypted even to someone viewing the configuration, with your code decrypting it at init.
Environment variables are not the right home for secrets that need rotation or tight access control. Anyone who can read the function configuration can see a plain variable. Store secrets in Secrets Manager or Parameter Store as a SecureString, put only the secret's name in an environment variable, fetch the value at init and cache it. Lambda also sets reserved variables of its own, such as AWS_REGION and AWS_LAMBDA_FUNCTION_NAME, and you cannot override those.
Timeouts
The function timeout ranges from 1 second to 900 seconds, which is the fifteen minute maximum. The default is 3 seconds, and many exam bugs are that default. When a function calls a slow dependency or processes a large file, raise the timeout above the worst case. When the work can exceed fifteen minutes, Lambda is the wrong tool for it in one piece: split it into steps with Step Functions, or run it on ECS or AWS Batch.
Inside the handler, use the context method for remaining time to stop cleanly before the timeout, for example to stop pulling more work from a list and hand the rest to another invocation. When a function times out, the invocation fails with a timeout error in the logs. What happens next depends on the invocation type, which the next section covers.
The execution role
Every function has an execution role, an IAM role that Lambda assumes on your behalf. The SDK inside the function picks up the role's temporary credentials automatically from the environment, so your code never handles keys. The role needs permission for everything the code calls: dynamodb:PutItem on the table, s3:GetObject on the object ARNs, kms:Decrypt on the key. It also needs permission to write logs, usually through the AWSLambdaBasicExecutionRole managed policy, which allows creating log groups and streams and putting log events. A function with no log permission still runs, but you see nothing in CloudWatch Logs, which makes debugging very hard. The IAM lesson covers policy evaluation; here, remember that AccessDeniedException from inside a function almost always means the execution role is missing an action.
Anything outside the handler runs during init and is reused on warm calls. Put SDK clients, connection pools and configuration there, but never state that must survive, because reuse is never guaranteed.