Page 3: Invoking and Testing Lambda Functions

3. Invoking and Testing Lambda Functions

After creating your function, you need to test it to ensure it works correctly. The AWS Console provides a convenient way to configure test events and invoke your function.

3.1. Configuring a Test Event

  1. On your Lambda function page, navigate to the "Test" tab.
  2. From the "Select a test event" dropdown, choose "Create new event".
  3. Select "Event template" and search for and select "hello-world".
  4. Specify an "Event name" like MyTestEvent.
  5. You can use the default JSON payload or modify it.
  6. Click "Save".

3.2. Invoking the Function and Checking Logs

  1. Click the "Test" button to invoke your function with the configured test event.
  2. The execution results will be displayed at the top of the page. Look for `StatusCode: 200` and `body: "Hello from Lambda!"` in the `Execution results` section.
  3. Expand the "Log output" section to view detailed execution logs recorded in CloudWatch Logs. These logs are crucial for debugging.

3.3. Invoking from other means (e.g., AWS CLI)

You can also invoke your Lambda function using the AWS CLI.

aws lambda invoke \
    --function-name my-first-lambda \
    --payload '{"key":"value"}' \
    output.json

This command saves the function's result to `output.json`.