Skip to content

Commit 4ab2c0a

Browse files
committed
feat: Adding Readme for enhanced-template
1 parent a7c8f8a commit 4ab2c0a

File tree

5 files changed

+409
-54
lines changed

5 files changed

+409
-54
lines changed

examples/NERDS/enhanced-template/enhanced-backend/README.md

Lines changed: 127 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ We will be working with an ehnahced task example where you will retrieve the tas
88

99
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:
1010

11-
![enhanced-recording](./enhanced-recording.gif)
11+
![enhanced-recording](./documentation/enhanced-backend.gif)
1212

13-
- `src` - Code for the express application and the APIs.
13+
## Folder Description
14+
15+
- `src` - Code for the express application and the APIs, and sample script to populate table.
1416
- `package.json` - Includes all the scripts to work on this project and the pre-requisites.
1517

1618
This application will create a couple of API methods to add and list the ToDos.
@@ -24,74 +26,69 @@ This application will create a couple of API methods to add and list the ToDos.
2426

2527
## Usage
2628

27-
To start working with this project you need to first run `npm install`.
28-
29-
### Running the tool in conjuntion with the front end.
30-
31-
![Demo](./documentation/Darn-basic-stack.gif)
32-
3329
### DynamoDB local
3430

3531
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.
3632

3733
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!
3834

39-
```shell
35+
To start working with this project you need to first run `npm install`.
36+
37+
```bash
4038
❯ npm run start-db
4139

42-
> basic-backend@0.0.1 start-db
40+
> enhanced-backend@0.0.1 start-db
4341
> echo "CID=$(docker run -p $npm_package_config_ddbport:$npm_package_config_ddbport -d amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb)" > .ddb_cid
44-
45-
Unable to find image 'amazon/dynamodb-local:latest' locally
46-
latest: Pulling from amazon/dynamodb-local
47-
decbb28a26fa: Pull complete
48-
4b968a8d55bd: Pull complete
49-
4f4fb700ef54: Pull complete
50-
16d147f186fa: Pull complete
51-
Digest: sha256:d7ebddeb60fa418bcda218a6c6a402a58441b2a20d54c9cb1d85fd5194341753
52-
Status: Downloaded newer image for amazon/dynamodb-local:latest
5342
```
5443

5544
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.
5645

5746
```shell
5847
❯ npm run stop-db
5948

60-
> basic-backend@0.0.1 stop-db
49+
> enhanced-backend@0.0.1 stop-db
6150
> source .ddb_cid && docker stop $CID && rm .ddb_cid
6251

6352
904e9a494f0f09acd027e33d275d3a51a05716f09cc4eace87b778bc3e65e650
6453
```
6554

6655
### Working with DynamoDB tables
6756

68-
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.
57+
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 `recipes-table` table, where you will store all your to-dos.
6958

70-
Run the command `npm run create-table`.
59+
Run the command command. `npm run create-recipes-table`
7160

72-
```shell
73-
❯ npm run create-table
61+
```bash
62+
❯ npm run create-recipes-table
7463

75-
> basic-backend@0.0.1 create-table
76-
> 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
64+
> enhanced-backend@0.0.1 create-recipes-table
65+
> aws dynamodb create-table --table-name $npm_package_config_ddbEnhancedTable --attribute-definitions AttributeName=PK,AttributeType=S AttributeName=SK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH AttributeName=SK,KeyType=RANGE --billing-mode PAY_PER_REQUEST --endpoint-url http://${npm_package_config_ddbhost}:${npm_package_config_ddbport} --no-cli-page
7766

7867
{
7968
"TableDescription": {
8069
"AttributeDefinitions": [
8170
{
8271
"AttributeName": "PK",
8372
"AttributeType": "S"
73+
},
74+
{
75+
"AttributeName": "SK",
76+
"AttributeType": "S"
8477
}
8578
],
86-
"TableName": "Notes",
79+
"TableName": "social-recipes",
8780
"KeySchema": [
8881
{
8982
"AttributeName": "PK",
9083
"KeyType": "HASH"
84+
},
85+
{
86+
"AttributeName": "SK",
87+
"KeyType": "RANGE"
9188
}
9289
],
9390
"TableStatus": "ACTIVE",
94-
"CreationDateTime": "2024-07-29T10:40:09.344000-04:00",
91+
"CreationDateTime": "2024-09-25T13:38:11.310000-04:00",
9592
"ProvisionedThroughput": {
9693
"LastIncreaseDateTime": "1969-12-31T19:00:00-05:00",
9794
"LastDecreaseDateTime": "1969-12-31T19:00:00-05:00",
@@ -101,54 +98,42 @@ Run the command `npm run create-table`.
10198
},
10299
"TableSizeBytes": 0,
103100
"ItemCount": 0,
104-
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/Notes",
101+
"TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/social-recipes",
105102
"BillingModeSummary": {
106103
"BillingMode": "PAY_PER_REQUEST",
107-
"LastUpdateToPayPerRequestDateTime": "2024-07-29T10:40:09.344000-04:00"
104+
"LastUpdateToPayPerRequestDateTime": "2024-09-25T13:38:11.310000-04:00"
108105
},
109106
"DeletionProtectionEnabled": false
110107
}
111108
}
112109
```
113110

114-
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`.
115-
116-
```shell
117-
❯ npm run create-table
118-
119-
> basic-backend@0.0.1 create-table
120-
> 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
121-
122-
123-
An error occurred (ResourceInUseException) when calling the CreateTable operation: Cannot create preexisting table
124-
```
125-
126111
### List all the existing tables
127112

128113
To idenfity which tables you have created execute the command `npm run show-tables`.
129114

130-
```shell
115+
```bash
131116
❯ npm run show-tables
132117

133-
> basic-backend@0.0.1 show-tables
134-
> aws dynamodb list-tables --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport
118+
> enhanced-backend@0.0.1 show-tables
119+
> aws dynamodb list-tables --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page
135120

136121
{
137122
"TableNames": [
138-
"Notes"
123+
"social-recipes"
139124
]
140125
}
141126
```
142127

143128
### Retrieve all the items from one table
144129

145-
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.
130+
List all the elements in the `social-recipes` table (Scan a table). `npm run scan-recipes`. However if your table is empty you will get this output.
146131

147-
```shell
148-
❯ npm run scan-table
132+
```bash
133+
❯ npm run scan-recipes
149134

150-
> basic-backend@0.0.1 scan-table
151-
> aws dynamodb scan --table-name $npm_package_config_ddbtable --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport
135+
> enhanced-backend@0.0.1 scan-recipes
136+
> aws dynamodb scan --table-name $npm_package_config_ddbEnhancedTable --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page
152137

153138
{
154139
"Items": [],
@@ -158,6 +143,96 @@ To return all the elements from the `Notes` table you can run the command `npm r
158143
}
159144
```
160145

146+
### Populate sample data
147+
148+
Populate the `social-recipes` table with sample fake data:
149+
150+
```bash
151+
❯ npm run populate-recipe-table
152+
153+
> enhanced-backend@0.0.1 populate-recipe-table
154+
> node src/populate.js
155+
156+
Successfully inserted batch of 7 items
157+
All items have been processed
158+
```
159+
160+
Scan the table one more time `npm run scan-recipes`
161+
162+
```bash
163+
❯ npm run scan-recipes
164+
165+
> enhanced-backend@0.0.1 scan-recipes
166+
> aws dynamodb scan --table-name $npm_package_config_ddbEnhancedTable --endpoint-url http://$npm_package_config_ddbhost:$npm_package_config_ddbport --no-cli-page
167+
168+
{
169+
"Items": [
170+
{
171+
"taskDate": {
172+
"S": "2024-09-21T10:35:39"
173+
},
174+
"SK": {
175+
"S": "TASK#0#2024-09-21T10:35:39#hUkIVS7H3BKlEmQTNvNOe"
176+
},
177+
"taskPriority": {
178+
"S": "0"
179+
},
180+
"description": {
181+
"S": "Corvina is the best for a seviche"
182+
},
183+
"PK": {
184+
"S": "USER#4Rl17WTewD6aa1-k73cBJ"
185+
},
186+
"title": {
187+
"S": "Get some Corvina"
188+
},
189+
"userId": {
190+
"S": "4Rl17WTewD6aa1-k73cBJ"
191+
},
192+
"taskId": {
193+
"S": "hUkIVS7H3BKlEmQTNvNOe"
194+
}
195+
},
196+
...
197+
...
198+
{
199+
"SK": {
200+
"S": "USER#4Rl17WTewD6aa1-k73cBJ"
201+
},
202+
"Priorities": {
203+
"L": [
204+
{
205+
"N": "0"
206+
},
207+
{
208+
"N": "1"
209+
},
210+
{
211+
"N": "2"
212+
},
213+
{
214+
"N": "3"
215+
}
216+
]
217+
},
218+
"PK": {
219+
"S": "USER#4Rl17WTewD6aa1-k73cBJ"
220+
},
221+
"userId": {
222+
"S": "4Rl17WTewD6aa1-k73cBJ"
223+
},
224+
"Name": {
225+
"S": "John Doe"
226+
}
227+
}
228+
],
229+
"Count": 7,
230+
"ScannedCount": 7,
231+
"ConsumedCapacity": null
232+
}
233+
234+
```
235+
161236
### Initialize the backend
162237

163238
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.
@@ -167,7 +242,7 @@ Tip: execute this command in a new terminal
167242
```shell
168243
❯ npm run start-backend
169244

170-
> basic-backend@0.0.1 start-backend
245+
> enhanced-backend@0.0.1 start-backend
171246
> node src/server.js
172247

173248
Server is running on port 3000

0 commit comments

Comments
 (0)