https://github.com/devteds/rails-with-aws-dynamodb
A simple Rails API application with AWS DynamoDB as its database with aws_record as ORM layer.
https://github.com/devteds/rails-with-aws-dynamodb
aws aws-dynamodb devcontainer docker docker-compose rails-api rails-api-backend ruby-on-rails vscode-devcontainer
Last synced: 15 days ago
JSON representation
A simple Rails API application with AWS DynamoDB as its database with aws_record as ORM layer.
- Host: GitHub
- URL: https://github.com/devteds/rails-with-aws-dynamodb
- Owner: devteds
- Created: 2024-08-27T16:22:03.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-27T22:39:35.000Z (10 months ago)
- Last Synced: 2025-02-13T13:18:47.879Z (4 months ago)
- Topics: aws, aws-dynamodb, devcontainer, docker, docker-compose, rails-api, rails-api-backend, ruby-on-rails, vscode-devcontainer
- Language: Ruby
- Homepage: https://www.devteds.com
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DynamoDB for Rails Application - A quick start
Follow the instructions in [this article for the step-by-step instruction](https://medium.com/@shettigarc/dynamodb-for-rails-developers-a-beginner-friendly-tutorial-669fe5a7b81a) on creating this Rails application and configuring AWS DynamoDB locally.
If you've read that and understand the steps, then here are the instructions on getting this app up and running. I use Docker & Docker Compose with [DevContainer](https://www.devteds.com/devcontainers-for-developers-multi-container-local-dev-setup/) and I primarily use VSCode. If you don't use VSCode, you can still get this running locally with docker & docker-compose.
## Setup Docker Environment: `DevContainer + Docker Compose`
```
cp .devcontainer/devcontainer-example.json .devcontainer/devcontainer.json
# Edit the devcontainer.json for path for user home directory containing .ssh or .aws. Or you can remove the mounts section completelycp docker-compose-example.yml docker-compose.yml
# Edit to change AWS credential variables
# Uncomment "command: tail -f /dev/null"
```VSCode (command pallete): `DevContainers > Rebuild and Reopen in Container`
Inside the container environment,
Bundle install:
```
bundle
```Let's create table and load some test data into the local DynamoDB:
```
rails aws_record:migrate
rails runner db/seeds.rb
```Verify the data on Rails console:
```
rails c
> Product.scan
```Run rails server:
```
rails s -b 0.0.0.0
```cURL or use the browser to hit: `http://localhost:/products`
```
curl -s http://localhost:3400/products | jq
curl -v http://localhost:3400/products
```## Setup Docker Compose Environment (No DevContainer or VSCode)
```
cp docker-compose-example.yml docker-compose.yml
# Edit to change AWS credential variables; update host ports for api & dynamodocker-compose build
```Run migratin, load some test data and verify using Rails Console:
```
docker-compose run --rm api bash
> bundle
> rails aws_record:migrate
> rails runner db/seeds.rb
> rails c
> Product.scan
> exit
> exit
```Run the app & verify
```
docker-compose up
```cURL or use the browser to hit: `http://localhost:/products`
```
curl -s http://localhost:3400/products | jq
curl -v http://localhost:3400/products
```## Tools & Versions I used
- MacOS - M1
- Docker 24.0.2, build cb74dfc
- Docker Compose version v2.18.1
- VSCode 1.87.2 (Universal)