Topic lessonTopic: Lambda and API Gateway: inputs, testing and failure investigation
Lambda test events: a beginner’s guide to JSON, returns and logs
A test event is JSON input supplied to a Lambda function. Define the input and expected return first, then read the returned value, function error and logs separately. Follow the process using a fictional function that calculates 6 × 7.
Define an expected result and record JSON syntax, handler-specific input requirements, returned values, logs and unverified integrations separately.
For readers who know that an event is input and a handler is the code entry point. No AWS account is needed to read this guide. This page creates or invokes no real function and collects no code or real data.
Decide what the test should establish
This guide covers synchronous testing of ordinary Lambda Event Functions. The event, handler and return have separate roles. The console’s Test action invokes the selected function synchronously; it does more than save input.
- Test event → HandlerSupply input
- Handler → Return / errorProcessing outcome
- Handler → LogsSeparate output
- Test event
- JSON input: length=6 and width=7.
- Handler
- Check the defined input contract, then calculate 6 × 7.
- Return / error
- The caller compares the result with the expected area=42.
- Logs
- Execution records, separate from the returned value.
Separate JSON syntax from the handler’s input contract
This example requires numeric length and width values, each from 0 to 100, and returns their product as area. These field names are the contract chosen for this example; other handlers require different fields.
{
"length": 6,
"width": 7
}{
"area": 42
}| Input | JSON syntax | Outcome in this fixed example |
|---|---|---|
| {"length":6,"width":7} | Valid | Return area=42 |
| {"length":6} | Valid | Handler validation rejects the missing width |
| {"length": | Malformed | This exercise stops at syntax checking before invocation |
Check invocation, returned values and logs
| Observation | What to inspect in this example | What it does not establish |
|---|---|---|
| Invocation API response | Synchronous Invoke status 200 and any FunctionError | 200 alone does not prove the calculation succeeded |
| Function return | Whether area=42 or an error was returned | A return does not by itself prove integration or log delivery |
| Logs | Whether records correspond to the execution being examined | Logs not appearing immediately do not alone prove no execution |
A synchronous Invoke can return API status 200 alongside a function error. Inspect FunctionError and the returned error details. A field named statusCode inside a function’s returned object is not the Invoke API’s HTTP status.
Input: {"length":6,"width":7}
Expected return: {"area":42}
API status (assumed): 200
Function result (modeled): completed
Observed return (modeled): {"area":42}
Log example (synthetic): MODEL_FIXED_HANDLER_RETURN
AWS log delivery: not observedReal CloudWatch Logs delivery depends on conditions including the execution role’s logging permissions and can be delayed. Check returned values and log arrival separately. This site’s synthetic logs are not retrieved from CloudWatch.
Change one condition and explain the difference
- Start with length=6 and width=7; compare the return with the expected value 42.
- Remove only width. Explain why the JSON remains valid while the handler’s input check fails.
- Compare malformed JSON and explain why this example stops at a different stage, before handler execution.
When you later use the real Lambda console
No AWS account is needed for this reading or the site’s fixed lab. Test in the real console executes a real function. Before trying it later, verify the learning target, account/Region, version or alias, permissions, external side effects and possible costs.
- Select an authorized learning function and verify which function/version will receive which input.
- On the Test tab, choose or create the event and compare fictional JSON with the expected outcome. Use Private where appropriate; do not save real data in shared test events.
- If you proceed with execution, choose Test and inspect the return or error in Execution result Details. Check logs separately; saving an event is not an execution result.
Keep unverified scope explicit
The fixed example teaches the relationship between supplied input and a stipulated handler. It does not verify a real trigger, AWS permissions, networking, dependencies, duration or duplicate handling. Even one successful real console event does not replace integration testing.
Record what you supplied, expected, observed and still have not observed. For example: the fixed JSON returns 42; missing width produces a handler error; AWS log delivery and invocation from an S3 notification remain unverified.
Check your interpretation
Choose an option to see the result and explanation.
Choose an option to see the result and explanation.
Choose an option to see the result and explanation.
Choose an option to see the result and explanation.
Choose an option to see the result and explanation.
Check, then explain in your own words
- Define the expected return from the input and handler contract.
- Read the invocation API response, returned value and logs separately.
- Change one condition and record observations and unverified scope.
Check your understanding: The fixed area handler errors after changing the input to {"length":6}. What did you establish, and what remains unverified?
The JSON is valid, but it lacks the width required by this handler. Real AWS execution, log delivery and trigger integration remain unverified.
Record syntax, handler requirements, observed outcomes and integration-test scope separately.
Sources and conditions checked
The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.
Scope and conditionsConsole JSON test events invoke synchronously. The area/hello/slow/fail handlers are fixed site examples, not built-in AWS operations.
Used in this lessonDecide what the test should establish When you later use the real Lambda console Check your interpretation
Scope and conditionsDistinguish 200 for RequestResponse from 202 for Event. Status codes do not replace function-error inspection. The model assumes acceptance/permissions and sends no API request.
Used in this lessonCheck invocation, returned values and logs When you later use the real Lambda console Check your interpretation
Scope and conditionsSeparate synchronous return values, function errors/logs and caller connection deadlines. Synthetic logs are neither retrieved logs nor a complete runtime log format.
Used in this lessonDecide what the test should establish Check invocation, returned values and logs
Scope and conditionsReal log delivery requires execution-role permissions and may be delayed. Returns and logs differ; fixed synthetic log examples do not establish actual log arrival.
Used in this lessonDecide what the test should establish Check invocation, returned values and logs
Scope and conditionsRetry ownership and conditions depend on invocation method/error type. Direct synchronous function errors are not automatically retried by Lambda; stream/queue mappings have distinct rules.
Used in this lessonWhen you later use the real Lambda console
Scope and conditionsSeparate handler input/logic tests from integration checks covering actual event delivery, configuration and permissions. A fixed example or single console test does not establish end-to-end success. Real cloud tests can affect resources and incur costs.
Used in this lessonSeparate JSON syntax from the handler’s input contract When you later use the real Lambda console Keep unverified scope explicit Check your interpretation