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 Mar 3, 2021
1 parent fa6b76a commit 9c8902c
Show file tree
Hide file tree
Showing 24 changed files with 1,645 additions and 48 deletions.

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 @@ -138,6 +139,7 @@ Mr Bean
"babel": Object {
"env": Object {
"cjs": Object {
"comments": true,
"presets": Array [
Array [
"@babel/env",
Expand All @@ -151,6 +153,7 @@ Mr Bean
],
},
"mjs": Object {
"comments": false,
"presets": Array [
Array [
"@babel/env",
Expand Down Expand Up @@ -184,6 +187,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 @@ -216,6 +220,7 @@ Mr Bean
"@typescript-eslint/parser": "^4.8.1",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"chokidar": "^3.4.3",
"eslint": "^7.13.0",
Expand All @@ -227,6 +232,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^2.0.0",
"typescript": "^4.0.5",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=12.19.0",
Expand Down Expand Up @@ -308,7 +314,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 @@ -393,6 +399,7 @@ Mr Bean
"babel": Object {
"env": Object {
"cjs": Object {
"comments": true,
"presets": Array [
Array [
"@babel/env",
Expand All @@ -406,6 +413,7 @@ Mr Bean
],
},
"mjs": Object {
"comments": false,
"presets": Array [
Array [
"@babel/env",
Expand Down Expand Up @@ -439,6 +447,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 @@ -471,6 +480,7 @@ Mr Bean
"@typescript-eslint/parser": "^4.8.1",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"chokidar": "^3.4.3",
"eslint": "^7.13.0",
Expand All @@ -482,6 +492,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^2.0.0",
"typescript": "^4.0.5",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=12.19.0",
Expand Down Expand Up @@ -563,7 +574,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 @@ -633,6 +644,7 @@ Mr Bean
"babel": Object {
"env": Object {
"cjs": Object {
"comments": true,
"presets": Array [
Array [
"@babel/env",
Expand All @@ -646,6 +658,7 @@ Mr Bean
],
},
"mjs": Object {
"comments": false,
"presets": Array [
Array [
"@babel/env",
Expand Down Expand Up @@ -679,6 +692,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 @@ -711,6 +725,7 @@ Mr Bean
"@typescript-eslint/parser": "^4.8.1",
"axios": "^0.21.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-knifecycle": "^5.0.0",
"chokidar": "^3.4.3",
"eslint": "^7.13.0",
Expand All @@ -722,6 +737,7 @@ Mr Bean
"rimraf": "^3.0.2",
"schema2dts": "^2.0.0",
"typescript": "^4.0.5",
"webpack": "4.44.2",
},
"engines": Object {
"node": ">=12.19.0",
Expand Down Expand Up @@ -803,7 +819,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
84 changes: 81 additions & 3 deletions packages/whook-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@

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

This is a basic [Whook](https://github.com/nfroidure/whook)
server demonstrating the various usages of the Whook framework to build
REST APIs.
This is a basic [Whook](https://github.com/nfroidure/whook) server demonstrating
the various usages of the Whook framework to build REST APIs.

## Usage

To run the server in production:

```sh
npm it
NODE_ENV=production npm start
Expand All @@ -27,6 +28,7 @@ NODE_ENV=production npm start
## Dev

Start the server in development:

```sh
# Simple dev mode
npm run dev
Expand All @@ -36,36 +38,112 @@ npm run watch
```

Create a new endpoint / service / provider or command:

```sh
npx whook create
```

List available commands:

```sh
npx whook ls
```

## Deploying with AWS Lambda

First install Terraform:

```sh
wget https://releases.hashicorp.com/terraform/0.14.0/terraform_0.14.0_linux_amd64.zip
mkdir .bin
unzip -d .bin terraform_0.14.0_linux_amd64.zip
rm terraform_0.14.0_linux_amd64.zip
```

Then initialize the Terraform configuration:

```sh
cd ./terraform
../.bin/terraform init;
```

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
```

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
npm run apitypes
```

## Debug

Execute a handler in isolation:

```sh
npx whook handler --name putEcho --parameters '{"body": { "echo": "YOLO!" }}'
```

Debug `whook` internals:

```sh
DEBUG=whook npm run dev
```

Debug `knifecycle` internals (dependency injection issues):

```sh
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 9c8902c

Please sign in to comment.