A simple demonstration of performing CRUD operations on DynamoDB using Node.js, TypeScript, and AWS SDK v3.
This project provides a practical example of performing CRUD (Create, Read, Update, Delete) operations on DynamoDB using Node.js, TypeScript, and the AWS SDK v3. It aims to showcase how to interact with DynamoDB for database operations and serve as a reference for integrating DynamoDB into your TypeScript applications.
- Create and Delete a DynamoDB table
- Insert items into the table
- Retrieve items from the table
- Update items in the table
- Delete items from the table
- Node.js (v14.17.5 or higher)
- npm (Node Package Manager)
- AWS CLI
- Docker
To run this project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/danielbrazrocha/node-ts-dynamodb-crud.git
-
Install the dependencies:
cd node-ts-dynamodb-crud npm install
-
Configure AWS credencials locally
aws configure
Use this simple configuration:
- AWS Access Key ID: anyid
- AWS Secret Access Key: anykey
- Default region name: local
-
Start a DynamoDB Local instance using Docker:
docker run -p 8000:8000 amazon/dynamodb-local
Note: Consider creating a Dockerfile for streamlined setup in the future.
-
Install and run DynamoDB Admin to view database changes:
npm install -g dynamodb-admin
-
Ensure the DynamoDB Local container is running.
-
Create the DynamoDB table:
npm run create-table
-
Seed the table with initial data:
npm run seed
-
Start the application:
npm run start
Once the project is up and running, you can access the following endpoints:
- Home Page: http://localhost:3221/
- Mail List Page: http://localhost:3221/mail/
- Individual Mail Page: http://localhost:3221/mail/US123456789CE
For convenience, the following CRUD commands are available to test in the package.json
file:
- Create:
npm run put-item
- Read:
npm run get-item
ornpm run get-item-by-pk
orget-all-items
- Update:
npm run update-item
- Delete:
npm run delete-item
Feel free to explore and modify these commands as needed.
Special thanks to James Hamann for the article and the AWS SDK v2 code base, which served as a reference for creating the v3 implementation with TypeScript. You can find the article here and the repository here