Skip to content

Commit

Permalink
feat(@whook/example): add AWS build to @whook/example
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Oct 28, 2020
1 parent 8ec8dd3 commit 3af939b
Show file tree
Hide file tree
Showing 21 changed files with 4,670 additions and 24 deletions.

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('initCreateWhook', () => {
dependencies: {
..._packageJSON.dependencies,
'@whook/authorization': '<current_version>',
'@whook/aws-lambda': '<current_version>',
'@whook/cli': '<current_version>',
'@whook/cors': '<current_version>',
'@whook/http-router': '<current_version>',
Expand Down Expand Up @@ -183,6 +184,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -214,6 +216,7 @@ Mr Bean
"@typescript-eslint/parser": "^3.9.1",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^3.0.1",
"chokidar": "^3.4.1",
"eslint": "^7.7.0",
Expand All @@ -224,6 +227,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^1.0.1",
"typescript": "^4.0.2",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=10.19.0",
Expand Down Expand Up @@ -316,7 +320,7 @@ Mr Bean
"lint": "eslint 'src/**/*.ts'",
"prettier": "prettier --write 'src/**/*.ts'",
"start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
"test": "npm run jest",
"test": "NODE_ENV=test npm run build && npm run jest",
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
"watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
Expand Down Expand Up @@ -447,6 +451,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -478,6 +483,7 @@ Mr Bean
"@typescript-eslint/parser": "^3.9.1",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^3.0.1",
"chokidar": "^3.4.1",
"eslint": "^7.7.0",
Expand All @@ -488,6 +494,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^1.0.1",
"typescript": "^4.0.2",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=10.19.0",
Expand Down Expand Up @@ -580,7 +587,7 @@ Mr Bean
"lint": "eslint 'src/**/*.ts'",
"prettier": "prettier --write 'src/**/*.ts'",
"start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
"test": "npm run jest",
"test": "NODE_ENV=test npm run build && npm run jest",
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
"watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
Expand Down Expand Up @@ -696,6 +703,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "<current_version>",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -727,6 +735,7 @@ Mr Bean
"@typescript-eslint/parser": "^3.9.1",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^3.0.1",
"chokidar": "^3.4.1",
"eslint": "^7.7.0",
Expand All @@ -737,6 +746,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^1.0.1",
"typescript": "^4.0.2",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=10.19.0",
Expand Down Expand Up @@ -829,7 +839,7 @@ Mr Bean
"lint": "eslint 'src/**/*.ts'",
"prettier": "prettier --write 'src/**/*.ts'",
"start": "NODE_ENV=\${NODE_ENV:-development} node bin/start",
"test": "npm run jest",
"test": "NODE_ENV=test npm run build && npm run jest",
"types": "rimraf -f 'dist/**/*.d.ts' && tsc --project . --declaration --emitDeclarationOnly --outDir dist",
"watch": "NODE_ENV=\${NODE_ENV:-development} DEV_MODE=1 DESTROY_SOCKETS=1 babel-node --extensions '.ts,.js' bin/watch",
"whook": "NODE_ENV=\${NODE_ENV:-development} whook",
Expand Down
58 changes: 58 additions & 0 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,52 @@ List available commands:
```sh
npx whook ls
```
## Deploying with AWS Lambda

First install Terraform:
```sh
wget https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip
mkdir .bin
unzip -d .bin terraform_0.12.24_linux_amd64.zip
rm terraform_0.12.24_linux_amd64.zip
```

Then initialize the Terraform configuration:
```sh
.bin/terraform init ./terraform;
```

Create a new workspace:
```sh
.bin/terraform workspace new staging
```

Build the lambdas:
```sh
NODE_ENV=staging npm run build
```

Build the commands Terraform depends on:
```sh
npm run compile
```

Plan the deployment:
```sh
.bin/terraform plan -out=terraform.plan terraform
```

Apply changes:
```sh
.bin/terraform apply terraform.plan
```

Finally retrieve the API URL and add and enjoy!
```sh
.bin/terraform output api_url
curl "$(.bin/terraform output api_url)staging/v3/ping"
# {"pong":"pong"}
```

Generate API types:
```sh
Expand All @@ -66,6 +112,18 @@ Debug `knifecycle` internals (dependency injection issues):
DEBUG=knifecycle npm run dev
```

Debug built lambdas:
```sh
## HTTP
NODE_ENV=staging npx whook testHTTPLambda --name putEcho \
--parameters '{ "body": { "echo": "Hey!" } }'
## Cron
NODE_ENV=staging npx whook testCronLambda --name handleMinutes
## Consumer
NODE_ENV=staging npx whook testConsumerLambda --name handleMessages \
--event '{ "Records": [{ "test": "test" }] }'
```

[//]: # (::contents:end)

# Authors
Expand Down
Loading

0 comments on commit 3af939b

Please sign in to comment.