How to Amplify: Create new Table - a2n-seattle/rms-app GitHub Wiki

  1. Create new table schema in amplify/ts-code/src/db/Schemas.ts.
/**
 * @param id Some unique id
 * ... other @param ...
 */
export const SOME_TABLE: string = process.env.STORAGE_SOME_NAME
export interface SomeSchema {
    id: string,
    ... other params ...
}
  1. Create amplify/ts-code/src/db/SomeTable.ts file.

This file will contain base methods for interacting with the database. Your API functions will call methods from this table file. See other Table.ts files for examples of different methods to implement.

  1. Add new table to amplify/ts-code/__dev__/db/LocalDBClient.ts
  • Add new interface to interface LocalDB.
  • Add to different methods of class LocalDBClient as needed.
  1. Modify seeds in amplify/resources/seeds, to account for new table.

Run npm run build && npm run test:unit to make sure that new seeds work.

  1. Run amplify storage add to add new table, with the following params:
? Select from one of the below mentioned services: NoSQL Database

✔ Provide a friendly name · tablename
✔ Provide table name · tablename

✔ What would you like to name this column · id
✔ Choose the data type · string
✔ Would you like to add another column? (Y/n) · no

Only one option for [Choose partition key for the table]. Selecting [id].

✔ Do you want to add a sort key to your table? (Y/n) · no

✔ Do you want to add global secondary indexes to your table? (Y/n) · no
✔ Do you want to add a Lambda Trigger for your Table? (y/N) · no

Note: Haven't figured out how to do it in the new CLI, but we need to modify ProvisionedThroughput = 1 for both ReadCapacityUnits and WriteCapacityUnits.

  1. Push the Pull Request! Once the PR goes through, then the GitHub Action Backend CD will push your new table to AWS!

  2. After request is merged, track deployment, make sure that deployment is successful and integration tests successfully run.

  3. Check that table has been added to DynamoDB in AWS console.