Test lambda functions

In this section we will create tests to see if the functions are working properly.

To test the functions, download the following file to your computer and run the command: aws dynamodb batch-write-item --request-items file://documentData.json

LambdaConsole

Test listing functions

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

LambdaConsole

  1. You will get all the information of the user’s files with the id abcd1234

LambdaConsole

Test creating function

  1. Open the upload_document function console
  2. Click Test tab
  • Enter tc_1 for event name
  • Enter the below json for 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 clickTest

LambdaConsole

  1. You will get a return result of succeeded

LambdaConsole

  1. Open Documents table to check if added successfully

LambdaConsole

Test deleting function

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

LambdaConsole

  1. You will get a return result of succeeded

LambdaConsole

  1. Open Documents table to check if deleted successfully

LambdaConsole

You are done creating Lambda functions that interact with DynamoDB. In the next post we will authenticate to the archive with the Amplify library.