Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
AWS · DVA-C03

Testing serverless applications

DVA-C03 · Lesson 17 of 24 · 2:22:07

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the DVA-C03 exam (AWS Certified Developer – Associate). In this lesson: unit, integration, and end-to-end tests, test events, sam local invoke, start-api, sam sync, and sam remote invoke, CDK assertions, mock integrations in API Gateway, and AI-assisted tests with Kiro. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Tested on a laptop

At AnyCompany Tickets, the tests of the pricing function only ran on a laptop, and a discount bug reached production. When the sandbox of the payment partner went down for two days, the front-end team could not work. And every developer typed sample events by hand. This lesson covers test events, local and cloud tests with SAM, tests of infrastructure with the CDK, mocks, and tests generated with AI.

Three kinds of tests

A serverless app needs three kinds of tests. Unit tests check the logic of a handler, with the AWS calls replaced by mocks, in seconds, on every change. Integration tests run the function in the cloud, against real services, in a test stack of its own. And end-to-end tests call the API the way a fan would, so permissions, quotas, and integrations are tested for real.

Test events

A test event is a JSON payload in the exact shape that a service sends: an S3 notification, a batch of SQS messages, or a proxy request from API Gateway. In the Lambda console, a private test event is only for its creator, while a shareable test event is visible to everyone in the account, saved as a schema in an EventBridge schema registry. The command sam local generate event writes sample payloads for many services, ready to edit. And API Gateway can test a method from its console, but the call is real: a method that deletes data really deletes it.

Testing with SAM

The SAM CLI runs functions on your machine, in containers built from the Lambda base images, so Docker must be running. The command sam local invoke runs a function once with an event file, and sam local start API serves the API on a local port, like three thousand, for tests with a browser or curl. The command sam sync, with the watch option, sends each code change to a development stack in seconds, and AWS says to use it only with development stacks. And sam remote invoke runs the deployed function in the cloud, with a shareable test event.

Testing infrastructure

With the CDK, the assertions module tests the template that a stack synthesizes, in seconds, with nothing deployed. Fine-grained assertions check what you name: a Lambda function with the expected runtime and timeout, or exactly one subscription to a topic. Snapshot tests compare the whole template with a saved copy, and flag every change, even in resources that no test names. And with CloudFormation, the same template deploys a separate test stack, where integration tests get their own resources, deleted after the run.

Mocks

External dependencies need stand-ins. In API Gateway, a mock integration returns a response from API Gateway itself, with a status code and a mapping template, and no backend at all. So the front-end team can build against the API before the backend exists, or while a partner's sandbox is down. And in unit tests, the SDK clients are replaced by mocks or stubs, so that the tests never reach AWS.

Tests with AI

AI tools take on the repetitive part of testing. In Kiro, the acceptance criteria of a spec become tests, and property-based tests check a rule against hundreds of generated inputs, like any fan and any seat, then shrink a failure to its smallest example. A hook runs the tests each time a file is saved, and in a pipeline, Kiro CLI in headless mode writes and runs tests, and explains the failures in the results. Each fixed bug gets a regression test that stays in the suite, and a coverage report shows which paths no test reaches, for the agent to cover. And the team still reviews every generated test.

Recap

Let's recap. Unit tests mock AWS, integration tests run in a test stack, and end-to-end tests call the API. Test events are JSON payloads, private or shareable, and sam local generate event writes samples. SAM runs functions and APIs locally in containers, and sam sync is for development stacks only. CDK assertions check named resources, and snapshot tests catch every change in the template. And mock integrations stand in for missing backends, while Kiro generates property-based and regression tests, which people still review.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. Three developers keep typing the same batch of SQS messages to test a function in the Lambda console. They want one saved event that all of them can use. What should the developer create?

    • A private test event for each developer
    • A shareable test event for the function
    • An SQS queue with sample messages in it
    • A mock integration in API Gateway
    Show the answer

    A shareable test event for the function

    A shareable test event is saved once, and everyone in the account can use it. “A private test event for each developer” would save one event per developer, visible only to its creator. “An SQS queue with sample messages in it” would send real messages, which does not give the console a test event. And “A mock integration in API Gateway” would give the API a fake backend, without testing the function at all.

  2. A team builds its stacks with the CDK. Reviewers must see any change in the synthesized template, even in resources that no test names. What should the developer add?

    • A fine-grained assertion on one resource
    • A sam local invoke run with a test event
    • A snapshot test of the synthesized template
    • A shareable test event in the console
    Show the answer

    A snapshot test of the synthesized template

    A snapshot test compares the whole template with the saved copy, so every change shows up. “A fine-grained assertion on one resource” would only check the resource that it names. “A sam local invoke run with a test event” would run the code of a function, without looking at the template. And “A shareable test event in the console” would give the console a sample payload, not a test of the infrastructure.

  3. A rule says that a discount never makes a ticket price negative, for any fan and any event. The example tests pass, but a bug in production broke the rule. What should the developer add with Kiro?

    • Property-based tests for the rule
    • More example tests for known cases
    • A steering file about the discounts
    • A hook that runs the linter on save
    Show the answer

    Property-based tests for the rule

    A property-based test checks the rule for many generated fans and events, and finds the inputs that break it. “More example tests for known cases” would only add the cases that someone thought of, like the tests that already passed. “A steering file about the discounts” would guide the code that Kiro writes, without testing anything. And “A hook that runs the linter on save” would check the style of the code, not the rule.