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
Document Data
documentData.json
(3 ko)
Test listing functions
Open the list_documents function console
Click Test tab
Enter tc_1
for event name
Enter the below json for Event JSON
{
"pathParameters": {
"id": "abcd1234"
}
}
Click Save , then click Test
You will get all the information of the user’s files with the id abcd1234
Test creating function
Open the upload_document function console
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"
}
}
Click Save , then clickTest
You will get a return result of succeeded
Open Documents table to check if added successfully
Test deleting function
Opent the delete_document function console
Click Test tab
Enter tc_1
for event name
Enter the below json for Event JSON
{
"pathParameters": {
"id": "abcd1234"
},
"queryStringParameters": {
"file": "aws-exports.js"
}
}
Click Save , then clickTest
You will get a return result of succeeded
Open Documents table to check if deleted successfully
You are done creating Lambda functions that interact with DynamoDB. In the next post we will authenticate to the archive with the Amplify library.