Preparation

We perform the following steps to prepare for authentication and file storage with Amplify Gen 2 in the next section:

  1. Check the Node.js and npm versions with the commands below:
node -v
npm -v

You need Node.js version 22.12 or later.
You should create an IAM user with the AdministratorAccess-Amplify permission and configure the credentials on your machine with the aws configure command, choosing ap-southeast-1 as the Default region name. Amplify will deploy resources to this region.

  1. Run the commands below to clone the application to your device:
git clone https://github.com/Hieu192/FCAJ-Serverless-DMS.git
cd FCAJ-Serverless-DMS
npm install
  1. Open the project and open the src/component/Home/Upload.jsx file. The line of code that calls the API to write document information to DynamoDB, right below the // Write document information to DynamoDB comment, is already commented out:
        // Write document information to DynamoDB
        // await api.post("/docs", item.info);

Preparation

We have not created the API yet, so we skip writing to DynamoDB for now. In the next workshop, you only need to uncomment this line after creating API Gateway.

  1. Run the following command to start the application, then open http://localhost:3000:
npm run dev
  • The application shows the Amplify is not configured message because the amplify_outputs.json file does not exist yet. This file will be created when we deploy the Amplify backend in the next section.
  • Press Ctrl + C in the terminal to stop the application.

Preparation

  1. To add Amplify Gen 2 to the application, run the command below from the application’s root folder:
npm create amplify@latest
  • At the Where should we create your project? (.) question, press Enter to create it in the current folder.
  • The command installs the Amplify backend libraries (@aws-amplify/backend, @aws-amplify/backend-cli, aws-cdk-lib, …) into devDependencies and creates the amplify folder with the following structure:
amplify/
├── auth/
│   └── resource.ts
├── data/
│   └── resource.ts
├── backend.ts
├── package.json
└── tsconfig.json

Preparation

The installation may take a few minutes.

  1. This workshop does not use Amplify Data because the document data is already stored in the DynamoDB table from the previous workshop.
  • Delete the amplify/data folder
  • Open the amplify/backend.ts file and replace its content with the code below:
import { defineBackend } from '@aws-amplify/backend';
import { auth } from './auth/resource';

defineBackend({
  auth,
});

Preparation

The backend.ts file is where all backend resources of the application are declared. For now, the backend only has the authentication part (auth). We will add the storage part (storage) in the next section.