Skip to content

Commit 618c435

Browse files
committed
add hotreloading capabilities
1 parent f1c0aa3 commit 618c435

File tree

5 files changed

+192
-8
lines changed

5 files changed

+192
-8
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ install:
1616
build:
1717
yarn && yarn build:backend;
1818

19+
hotreload:
20+
yarn && yarn hotreload:backend;
21+
1922
bootstrap:
2023
yarn cdklocal bootstrap;
2124

@@ -34,6 +37,9 @@ prepare-frontend-local:
3437
build-frontend:
3538
yarn build:frontend
3639

40+
start-frontend:
41+
yarn start:frontend
42+
3743
bootstrap-frontend:
3844
yarn cdklocal bootstrap --app="node dist/aws-sdk-js-notes-app-frontend.js";
3945

@@ -54,4 +60,12 @@ ready:
5460
logs:
5561
@localstack logs > logs.txt
5662

63+
setup-challenge:
64+
yarn install
65+
make build
66+
make bootstrap
67+
make deploy
68+
make prepare-frontend-local
69+
make hotreload
70+
5771
.PHONY: usage install run start stop ready logs

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"cdk": "cd packages/infra && yarn cdk",
1010
"cdklocal": "cd packages/infra && yarn cdklocal",
1111
"build:backend": "cd packages/backend && yarn build",
12+
"hotreload:backend": "cd packages/backend && yarn hotreload",
1213
"prepare:frontend": "node packages/scripts/populate-frontend-config.js",
1314
"prepare:frontend-local": "node packages/scripts/populate-frontend-config.js --local",
1415
"build:frontend": "cd packages/frontend && yarn build",

packages/backend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
"description": "Backend for notes app created using modular AWS SDK for JavaScript",
66
"dependencies": {
77
"@aws-sdk/client-dynamodb": "3.245.0",
8-
"@aws-sdk/util-dynamodb": "3.245.0"
8+
"@aws-sdk/util-dynamodb": "3.245.0",
9+
"nodemon": "^3.1.7"
910
},
1011
"scripts": {
1112
"build": "tsc --noEmit && node build.js",
1213
"build:backend": "cd .. && yarn build:backend",
14+
"hotreload": "nodemon --watch src --ext '*' --exec 'node build.js'",
1315
"cdk": "cd .. && yarn cdk"
1416
},
1517
"keywords": [

packages/infra/cdk/notes-api.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { aws_dynamodb as dynamodb, aws_lambda as lambda } from "aws-cdk-lib";
1+
import {
2+
aws_dynamodb as dynamodb,
3+
aws_lambda as lambda,
4+
aws_s3 as s3,
5+
} from "aws-cdk-lib";
26
import { Construct } from "constructs";
37

48
export interface NotesApiProps {
@@ -21,7 +25,10 @@ export class NotesApi extends Construct {
2125
runtime: lambda.Runtime.NODEJS_18_X,
2226
handler: "app.handler",
2327
// ToDo: find a better way to pass lambda code
24-
code: lambda.Code.fromAsset(`../backend/dist/${id}`),
28+
code: lambda.Code.fromBucket(
29+
s3.Bucket.fromBucketName(this, "hot-reload", "hot-reload"),
30+
`${__dirname}/../../backend/dist/${id}`
31+
),
2532
environment: {
2633
NOTES_TABLE_NAME: table.tableName,
2734
},

0 commit comments

Comments
 (0)