Skip to content

Commit 0ad2bab

Browse files
authored
Merge pull request #146 from tebanieo/feat--NERDS-stack-basic-stack
feat: base code for the NERDS stack, renaming from DRESN stack
2 parents 334ba08 + 208f148 commit 0ad2bab

File tree

26 files changed

+845
-6
lines changed

26 files changed

+845
-6
lines changed

examples/DRESN/basic-template/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# 🔥 DRESN - DynamoDB React Express SAM NodeJS 🔥
1+
# 🔥 NERDS - NodeJS Express React DynamoDB and SAM 🔥
22

3-
Welcome to the DRESN stack - a sizzling hot combination of DynamoDB, React, Express, SAM, and Node.js. This setup will help you bootstrap your application development by connecting it to a DynamoDB table, which provides virtually unlimited scale and low latency with the benefits of a managed service.
3+
Welcome to the NERDS stack - a sizzling hot combination of DynamoDB, React, Express, SAM, and Node.js. This setup will help you bootstrap your application development by connecting it to a DynamoDB table, which provides virtually unlimited scale and low latency with the benefits of a managed service.
44

5-
## 🚀 Benefits of the DRESN Stack
5+
## 🚀 Benefits of the NERDS Stack
66

7-
The DRESN stack offers a powerful set of tools and technologies that work together seamlessly to build scalable and robust web applications:
7+
The NERDS stack offers a powerful set of tools and technologies that work together seamlessly to build scalable and robust web applications:
88

99
**DynamoDB:** As the backbone of the stack, DynamoDB provides a highly scalable and fully managed NoSQL database service. With its flexible data model, fast performance, and automatic scaling, DynamoDB is an ideal choice for modern, data-intensive applications.
1010

@@ -20,7 +20,7 @@ By combining these powerful technologies, the DRESN stack provides a comprehensi
2020

2121
## 🛠️ Getting Started
2222

23-
To get started with the DRESN stack, navigate to the folders with the stack at different stages.
23+
To get started with the NERDS stack, navigate to the folders with the stack at different stages.
2424

2525
### 🎨 Basic Template
2626

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Basic Template
2+
3+
In this example you will build the TaskMaster application!
4+
5+
![TaskMaster](./basic-backend/documentation/TaskMaster.png)
6+
7+
To execute this project please:
8+
9+
1. Open the [basic-backend](./basic-backend/README.md) folder with instructions to execute the backend locally.
10+
2. Open the [basic-frontend](./basic-frontend/README.md) folder with instructions to execute the front end and run your web applicaation locally.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-json
8+
- id: detect-aws-credentials
9+
args: ["--allow-missing-credentials"]
10+
- id: detect-private-key
11+
- repo: https://github.com/Yelp/detect-secrets
12+
rev: v1.5.0
13+
hooks:
14+
- id: detect-secrets
15+
args: ["--baseline", ".secrets.baseline"]
16+
exclude: Pipfile.lock
17+
- repo: https://github.com/pre-commit/mirrors-prettier
18+
rev: v3.1.0
19+
hooks:
20+
- id: prettier
21+
- repo: https://github.com/awslabs/cfn-python-lint
22+
rev: v1.8.2 # The version of cfn-lint to use
23+
hooks:
24+
- id: cfn-python-lint
25+
files: templates/.*\.(json|yml|yaml)$
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Esteban Serna
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# NERDS Stack - Basic Project - NodeJS Express React DynamoDB and SAM
2+
3+
The NERDS stack will allow you to bootstrap your work with DynamoDB, you can move from Development to Production very quickly.
4+
5+
This project contains source code and supporting files for a sample application running on Express and NodeJS with Amazon DynamoDB local. It includes the following files and folders:
6+
7+
- `src` - Code for the express application and the APIs.
8+
- `package.json` - Includes all the scripts to work on this project and the pre-requisites.
9+
10+
This application will create a couple of API methods to add and list the ToDos.
11+
12+
## Requirements
13+
14+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/)
15+
- [DynamoDB Local Docker Image](https://hub.docker.com/r/amazon/dynamodb-local)
16+
- [Node v22.3.0](https://nodejs.org/en/blog/release/v22.3.0)
17+
- [AWS JavaScript SDK v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/)
18+
19+
## Usage
20+
21+
To start working with this project you need to first run `npm install`.
22+
23+
### Running the tool in conjuntion with the front end.
24+
25+
![Demo](./documentation/Darn-basic-stack.gif)
26+
27+
### DynamoDB local
28+
29+
This application will store all the information in an Amazon DynamoDB local instance, you will experience all the benefits from Amazon DynamoDB in your workstation.
30+
31+
Execute the command `npm run start-db`. If this is the first time running the command your output should look like the one below. Docker will obtain the latest version for you!
32+
33+
```shell
34+
❯ npm run start-db
35+
36+
> basic-backend@0.0.1 start-db
37+
> echo "CID=$(docker run -p $npm_package_config_ddbport:$npm_package_config_ddbport -d amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb)" > .ddb_cid
38+
39+
Unable to find image 'amazon/dynamodb-local:latest' locally
40+
latest: Pulling from amazon/dynamodb-local
41+
decbb28a26fa: Pull complete
42+
4b968a8d55bd: Pull complete
43+
4f4fb700ef54: Pull complete
44+
16d147f186fa: Pull complete
45+
Digest: sha256:d7ebddeb60fa418bcda218a6c6a402a58441b2a20d54c9cb1d85fd5194341753
46+
Status: Downloaded newer image for amazon/dynamodb-local:latest
47+
```
48+
49+
If you want to stop DynamoDB local execution you just need to run the command `npm run stop-db`. The long number at the end represents your docker container ID.
50+
51+
```shell
52+
❯ npm run stop-db
53+
54+
> basic-backend@0.0.1 stop-db
55+
> source .ddb_cid && docker stop $CID && rm .ddb_cid
56+
57+
904e9a494f0f09acd027e33d275d3a51a05716f09cc4eace87b778bc3e65e650
58+
```
59+
60+
### Working with DynamoDB tables
61+
62+
This project consists of a To-Do application and you will be storing all the items in a DynamoDB table. First you need to create a `Notes` table, where you will store all your to-dos.
63+
64+
Run the command `npm run create-table`.
65+
66+
```shell
67+
❯ npm run create-table
68+
69+
> basic-backend@0.0.1 create-table
70+
> aws dynamodb create-table --table-name $npm_package_config_ddbtable --attribute-definitions AttributeName=PK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH --billing-mode PAY_PER_REQUEST --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page
71+
72+
{
73+
"TableDescription": {
74+
"AttributeDefinitions": [
75+
{
76+
"AttributeName": "PK",
77+
"AttributeType": "S"
78+
}
79+
],
80+
"TableName": "Notes",
81+
"KeySchema": [
82+
{
83+
"AttributeName": "PK",
84+
"KeyType": "HASH"
85+
}
86+
],
87+
"TableStatus": "ACTIVE",
88+
"CreationDateTime": "2024-07-29T10:40:09.344000-04:00",
89+
"ProvisionedThroughput": {
90+
"LastIncreaseDateTime": "1969-12-31T19:00:00-05:00",
91+
"LastDecreaseDateTime": "1969-12-31T19:00:00-05:00",
92+
"NumberOfDecreasesToday": 0,
93+
"ReadCapacityUnits": 0,
94+
"WriteCapacityUnits": 0
95+
},
96+
"TableSizeBytes": 0,
97+
"ItemCount": 0,
98+
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Notes",
99+
"BillingModeSummary": {
100+
"BillingMode": "PAY_PER_REQUEST",
101+
"LastUpdateToPayPerRequestDateTime": "2024-07-29T10:40:09.344000-04:00"
102+
},
103+
"DeletionProtectionEnabled": false
104+
}
105+
}
106+
```
107+
108+
If you run the command twice by mistake, the second time you will get an error saying that you already have a table called `Notes`.
109+
110+
```shell
111+
❯ npm run create-table
112+
113+
> basic-backend@0.0.1 create-table
114+
> aws dynamodb create-table --table-name $npm_package_config_ddbtable --attribute-definitions AttributeName=PK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH --billing-mode PAY_PER_REQUEST --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page
115+
116+
117+
An error occurred (ResourceInUseException) when calling the CreateTable operation: Cannot create preexisting table
118+
```
119+
120+
### List all the existing tables
121+
122+
To idenfity which tables you have created execute the command `npm run show-tables`.
123+
124+
```shell
125+
❯ npm run show-tables
126+
127+
> basic-backend@0.0.1 show-tables
128+
> aws dynamodb list-tables --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport
129+
130+
{
131+
"TableNames": [
132+
"Notes"
133+
]
134+
}
135+
```
136+
137+
### Retrieve all the items from one table
138+
139+
To return all the elements from the `Notes` table you can run the command `npm run scan-table`. However if your table is empty you will get this output.
140+
141+
```shell
142+
❯ npm run scan-table
143+
144+
> basic-backend@0.0.1 scan-table
145+
> aws dynamodb scan --table-name $npm_package_config_ddbtable --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport
146+
147+
{
148+
"Items": [],
149+
"Count": 0,
150+
"ScannedCount": 0,
151+
"ConsumedCapacity": null
152+
}
153+
```
154+
155+
### Initialize the backend
156+
157+
Finally to work with the sample express application, included in this project you will need to execute the instruction `npm run start-backend`, this process will start the express application that will be listening at port 3000.
158+
159+
Tip: execute this command in a new terminal
160+
161+
```shell
162+
❯ npm run start-backend
163+
164+
> basic-backend@0.0.1 start-backend
165+
> node src/server.js
166+
167+
Server is running on port 3000
168+
```
169+
170+
## Contributing
171+
172+
As soon as you clone this repository you need to run `pre-commit install` and before pushing any commit you need to run `detect-secrets scan > .secrets.baseline`. Failing to run this command will result in an invalid commit and it will be rejected.
30.1 MB
Loading
40.5 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "basic-backend",
3+
"description": "Enhanced backend project sample for the NodeJS Express React DynamoDB and SAM (NERDS) Stack",
4+
"version": "0.0.1",
5+
"private": true,
6+
"dependencies": {
7+
"@aws-sdk/client-dynamodb": "^3.620.0",
8+
"@aws-sdk/lib-dynamodb": "^3.620.0",
9+
"@aws-sdk/util-dynamodb": "^3.620.0",
10+
"aws-sdk": "^2.1664.0",
11+
"body-parser": "^1.20.2",
12+
"cors": "^2.8.5",
13+
"express": "^4.19.2",
14+
"nanoid": "^5.0.7"
15+
},
16+
"type": "module",
17+
"config": {
18+
"ddbhost": "0.0.0.0",
19+
"ddbport": "8000",
20+
"ddbtable": "Tasks"
21+
},
22+
"scripts": {
23+
"start-db": "echo \"CID=$(docker run -p $npm_package_config_ddbport:$npm_package_config_ddbport -d amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb)\" > .ddb_cid",
24+
"stop-db": "source .ddb_cid && docker stop $CID && rm .ddb_cid",
25+
"start-backend": "node src/server.js",
26+
"create-table": "aws dynamodb create-table --table-name $npm_package_config_ddbtable --attribute-definitions AttributeName=PK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH --billing-mode PAY_PER_REQUEST --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page",
27+
"show-tables": "aws dynamodb list-tables --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page",
28+
"scan-table": "aws dynamodb scan --table-name $npm_package_config_ddbtable --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page"
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"5.1.3","start":"2024-08-15T19:18:49.327Z","data":[],"messages":[],"errors":[],"time":0.021}

0 commit comments

Comments
 (0)