Test Lambda functions

In this section, we will check whether the functions work properly.

  • To test the functions, click documentData.json below to download the file directly to your computer:

  • Run the following command to write data to the table: aws dynamodb batch-write-item --request-items file://documentData.json and the data in the Documents table will be displayed as shown below.

LambdaConsole

Test listing function

  1. Open the list_documents function console
  2. Click the Test tab
  • Enter tc_1 as the event name
  • Enter the JSON below in Event JSON
{
  "pathParameters": {
    "id": "abcd1234"
  }
}
  1. Click Save, then click Test

LambdaConsole LambdaConsole LambdaConsole

  1. You will receive all information about the user’s files with ID abcd1234

LambdaConsole

Test adding function

  1. Open the upload_document function console
  2. Click the Test tab
  • Enter tc_1 as the event name
  • Enter the JSON below in Event JSON
{
  "body": {
      "user_id": "abcd1234",
      "file": "aws_serverless.doc",
      "folder": "",
      "identityId": "123456cvbn",
      "modified": "13-03-2023",
      "size": "2MB",
      "type": "doc",
      "tag": "aws, serverless"
  }
}
  1. Click Save, then click Test

LambdaConsole LambdaConsole LambdaConsole

  1. The returned result will be succeeded

LambdaConsole

  1. Open the Documents table to check whether the data was added successfully

LambdaConsole

Test deleting function

  1. Open the delete_document function console
  2. Click the Test tab
  • Enter tc_1 as the event name
  • Enter the JSON below in Event JSON
{
  "pathParameters": {
    "id": "abcd1234"
  },
  "queryStringParameters": {
    "file": "aws-exports.js"
  }
}
  1. Click Save, then click Test

LambdaConsole LambdaConsole LambdaConsole

  1. The returned result will be succeeded

LambdaConsole

  1. Open the Documents table to check whether the item was deleted successfully

LambdaConsole

You have completed creating Lambda functions that interact with DynamoDB. In the next workshop, we will implement authentication and storage with the Amplify library.