Test APIs With Front-end

After testing that the APIs work correctly with Postman, we will test the APIs called from the front-end in the FCAJ-Serverless-DMS folder of workshop 134.

  1. Open the src/constant.js file in the FCAJ-Serverless-DMS folder
  • Replace the value of APP_API_URL with the Invoke URL of the dev stage that you noted down:
export const APP_API_URL = "https://e5drpttp24.execute-api.ap-southeast-1.amazonaws.com/dev";

WebApp

  1. Open the src/component/Home/Upload.jsx file. Uncomment the line of code that calls the API to write document information to DynamoDB, right below the // Write document information to DynamoDB comment:
        // Write document information to DynamoDB
        await api.post("/docs", item.info);

WebApp

  1. Run the commands below in the root folder of the project to rebuild the application and upload it to the S3 bucket:
npm run build
aws s3 cp dist s3://BUCKET_NAME --recursive
  • Replace BUCKET_NAME with the name of the bucket you created in section 1.

WebApp

  1. Go back to the web application from section 1, reload the page (Ctrl + F5) to get the new build. Sign in with the email and password you registered in workshop 134.
  • Click Upload

WebApp

  1. Click Add files
  • Select the files you want to upload
  • You can enter tags or skip this step
  • Click Upload

WebApp

  1. Go back to the DynamoDB console and click the Refresh icon to see the result.

WebApp

  • Open the console of the S3 bucket whose name starts with amplify-fcajdms- created in workshop 134, check that the files have been uploaded to the protected/{Identity ID}/ folder.

WebApp

  • Go back to the application, select Home in the left menu. Used Storage and Amount of Files show the total size and the number of files you have uploaded.

WebApp

  1. Select My Document in the left menu. You will see the list of files you just uploaded.
  • Click Select to switch to delete mode

WebApp

  • Select the file you want to delete
  • Click Delete

WebApp

  • Click OK to confirm deleting the file.

WebApp

  • The file has been deleted

WebApp

  • Check the Documents table

WebApp

  • And you can click the download icon to download a file you want

WebApp

In the browser Console, you may see the following two kinds of errors; this is expected:

  • A 404 (Not Found) error when you reload the page at paths such as /document: S3 returns the index.html file set as the Error document, and the application still shows the correct page.
  • A CORS error when you type a keyword in the Search… box: the search API will be created in workshop 138; for now the application shows the Search is not available message.

We have finished deploying and testing the API. In workshop 136, we will create all the resources again with the AWS Serverless Application Model (AWS SAM), so you should clean up the resources of this workshop before moving on to the next one.