Test API With Front-end

We will connect the front-end in the FCAJ-Serverless-DMS folder to the REST API we just created, then upload, download and delete documents to test the APIs.

  1. Open the CloudFormation console, select the fcajdms stack, then select the Outputs tab and write down the ApiUrl value. This is the Invoke URL of the dev stage, for example: https://e5drpttp24.execute-api.ap-southeast-1.amazonaws.com/dev

TestAPI

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

TestAPI

The SAM stack creates a new REST API, so ApiUrl is different from the Invoke URL you used in workshop 135. You must replace this value.

  1. Open the src/component/Home/Upload.jsx file. Check that the line that calls the API to write document information to DynamoDB, right below the // Write document information to DynamoDB comment, is uncommented:
        // Write document information to DynamoDB
        await api.post("/docs", item.info);
  • If you followed workshop 135, this line is already uncommented. If you just downloaded the project, uncomment this line.

TestAPI

  1. Run the commands below in the root folder of the project to rebuild the application and upload it to the S3 bucket that hosts the website:
npm run build
aws s3 cp dist s3://WEB_STORE_BUCKET --recursive
  • Replace WEB_STORE_BUCKET with the WebStoreBucket value in the Outputs tab of the fcajdms stack.

TestAPI

  1. Open the web application again with the WebsiteURL value and reload the page (Ctrl + F5) to get the new build. Sign in with the email and password you registered in part 1.2.
  • Click Upload

TestAPI

  1. Click Add files
  • Select the files you want to upload
  • Enter a tag or skip it
  • Click Upload

TestAPI

  1. Open the DynamoDB console, select Explore items on the left menu, then select the Documents table. You will see the information of the files you uploaded.

TestAPI

  • Open the S3 console, select the bucket whose name starts with fcajdmsstore- (the DocumentStoreBucket value), and check that the files were uploaded to the protected/{Identity ID}/ folder.

TestAPI

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

TestAPI

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

TestAPI

  • Select the files you want to delete
  • Click Delete

TestAPI

  • Click OK to confirm the deletion.

TestAPI

  • The file has been deleted

TestAPI

  • Check the Documents table; the information of the file has been deleted.

TestAPI

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

TestAPI

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

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

We have deployed the serverless application with AWS SAM. In workshop 137, we will set up CloudFront and SSL for the web application.