INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

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.

What you will learn

Define an expected result and record JSON syntax, handler-specific input requirements, returned values, logs and unverified integrations separately.

Prerequisite

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.

Follow the input into processing; inspect returns and logs separately
Follow the input into processing; inspect returns and logs separately1: Test event — Supply input — Handler. 2: Handler — Processing outcome — Return / error. 3: Handler — Separate output — Logs123Test eventHandlerReturn / errorLogsFollow the input into processing; inspect returns and logs separately1: Test event — Supply input — Handler. 2: Handler — Processing outcome — Return / error. 3: Handler — Separate output — Logs123Test eventHandlerReturn / errorLogs
  1. Test event → HandlerSupply input
  2. Handler → Return / errorProcessing outcome
  3. 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.

Input JSON for the fixed area handler
{
  "length": 6,
  "width": 7
}
Expected return for this input
{
  "area": 42
}
Similar inputs can fail at different stages
InputJSON syntaxOutcome in this fixed example
{"length":6,"width":7}ValidReturn area=42
{"length":6}ValidHandler validation rejects the missing width
{"length":MalformedThis exercise stops at syntax checking before invocation

Check invocation, returned values and logs

Avoid one undifferentiated success label
ObservationWhat to inspect in this exampleWhat it does not establish
Invocation API responseSynchronous Invoke status 200 and any FunctionError200 alone does not prove the calculation succeeded
Function returnWhether area=42 or an error was returnedA return does not by itself prove integration or log delivery
LogsWhether records correspond to the execution being examinedLogs 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.

Teaching record, not an AWS log format
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 observed

Real 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

  1. Start with length=6 and width=7; compare the return with the expected value 42.
  2. Remove only width. Explain why the JSON remains valid while the handler’s input check fails.
  3. 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.

  1. Select an authorized learning function and verify which function/version will receive which input.
  2. 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.
  3. 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.

How does the console Test action invoke a function with a test event?
Read the answer and reason

Answer: Synchronously · Check input, execution and observations separately.

Choose an option to see the result and explanation.

The fixed area handler rejects {"length":6} for missing width. What should you inspect?
Read the answer and reason

Answer: The handler’s required fields · Check input, execution and observations separately.

Choose an option to see the result and explanation.

A synchronous Invoke returns 200 with FunctionError. Can you conclude that the intended work succeeded?
Read the answer and reason

Answer: Inspect the returned error and payload · Check input, execution and observations separately.

Choose an option to see the result and explanation.

A synthetic log example appears in this site. What has been established?
Read the answer and reason

Answer: How to read the fixed example’s record · Check input, execution and observations separately.

Choose an option to see the result and explanation.

One fictional event succeeds in the console. Does that verify the S3 notification integration?
Read the answer and reason

Answer: Verify the integration separately · Check input, execution and observations separately.

Check, then explain in your own words

  1. Define the expected return from the input and handler contract.
  2. Read the invocation API response, returned value and logs separately.
  3. 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.