This repository is a simple example project using DynamoDB with the Go AWS SDK V2 and Docker Compose.
Prerequisites
Docker and Docker Compose
Go
Steps to Execute
Install dependencies: go get ./...
Run docker-compose up to start the DynamoDB container.
Run go run ./cmd/main.go to execute the Go application.
To stop and remove Docker containers
docker-compose down
Explanation
The setup involves the creation of the database structure in the SetupDatabase function. It checks if the MainSingleTable exists; if not, it creates the table. The table structure consists of a 'pk' and an 'sk' following the SingleTable Desing, with the example entity User having the key definition:
pk: USER#username
sk: USER#username
After table is created, three users are inserted using 'PutItem'. Finally, the user with the username 'seconduser' is retrieved using 'GetItem'.
How to Check the Data
You can install NoSQL Workbench for DynamoDB for a comprehensive view.
The Docker Compose runs a Node image with DynamoDB Admin GUI installed. Access it at 'localhost:8001'.