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 Apr 5, 2020
1 parent bd0f39b commit b730dc9
Show file tree
Hide file tree
Showing 21 changed files with 1,429 additions and 19 deletions.

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "^3.1.3",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -202,6 +203,7 @@ Mr Bean
"@typescript-eslint/parser": "^2.26.0",
"axios": "^0.19.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-knifecycle": "^1.2.0",
"eslint": "^6.8.0",
"eslint-plugin-prettier": "^3.1.2",
Expand All @@ -211,6 +213,7 @@ Mr Bean
"prettier": "^2.0.2",
"rimraf": "^3.0.2",
"typescript": "^3.8.3",
"webpack": "4.41.5",
},
"engines": Object {
"node": ">=10.19.0",
Expand Down Expand Up @@ -425,6 +428,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "^3.1.3",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -455,6 +459,7 @@ Mr Bean
"@typescript-eslint/parser": "^2.26.0",
"axios": "^0.19.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-knifecycle": "^1.2.0",
"eslint": "^6.8.0",
"eslint-plugin-prettier": "^3.1.2",
Expand All @@ -464,6 +469,7 @@ Mr Bean
"prettier": "^2.0.2",
"rimraf": "^3.0.2",
"typescript": "^3.8.3",
"webpack": "4.41.5",
},
"engines": Object {
"node": ">=10.19.0",
Expand Down Expand Up @@ -663,6 +669,7 @@ Mr Bean
},
"dependencies": Object {
"@whook/authorization": "<current_version>",
"@whook/aws-lambda": "^3.1.3",
"@whook/cli": "<current_version>",
"@whook/cors": "<current_version>",
"@whook/http-router": "<current_version>",
Expand Down Expand Up @@ -693,6 +700,7 @@ Mr Bean
"@typescript-eslint/parser": "^2.26.0",
"axios": "^0.19.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-knifecycle": "^1.2.0",
"eslint": "^6.8.0",
"eslint-plugin-prettier": "^3.1.2",
Expand All @@ -702,6 +710,7 @@ Mr Bean
"prettier": "^2.0.2",
"rimraf": "^3.0.2",
"typescript": "^3.8.3",
"webpack": "4.41.5",
},
"engines": Object {
"node": ">=10.19.0",
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 @@ -40,6 +40,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"}
```

## Debug
Execute a handler in isolation:
Expand All @@ -57,6 +103,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
14 changes: 11 additions & 3 deletions packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
"testsFiles": "'src/**/*.test.ts'",
"distFiles": "'dist/**/*.js'",
"ignore": [
"dist"
"dist",
"builds",
".bin",
".terraform",
"*.plan",
"*.tfstate.d"
],
"bundleFiles": [
"bin",
Expand All @@ -57,7 +62,7 @@
"prettier": "prettier --write 'src/**/*.ts'",
"preversion": "npm run compile",
"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",
"whook": "NODE_ENV=${NODE_ENV:-development} whook",
"whook-dev": "PROJECT_SRC=\"$PWD/src\" NODE_ENV=${NODE_ENV:-development} babel-node --extensions '.ts,.js' -- node_modules/@whook/cli/bin/whook.js"
Expand All @@ -78,6 +83,7 @@
"homepage": "https://github.com/nfroidure/whook",
"dependencies": {
"@whook/authorization": "^3.1.3",
"@whook/aws-lambda": "^3.1.3",
"@whook/cli": "^3.1.3",
"@whook/cors": "^3.1.3",
"@whook/http-router": "^3.1.3",
Expand Down Expand Up @@ -107,7 +113,9 @@
"@typescript-eslint/parser": "^2.26.0",
"axios": "^0.19.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-knifecycle": "^1.2.0",
"webpack": "4.41.5",
"eslint": "^6.8.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^25.2.4",
Expand Down Expand Up @@ -237,4 +245,4 @@
],
"testEnvironment": "node"
}
}
}
13 changes: 10 additions & 3 deletions packages/whook-example/src/__snapshots__/cli.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ Object {
",
"stdout": "
# Provided by \\"@whook/example\\": 1 commands
# Provided by \\"@whook/example\\": 2 commands
- printEnv: A command printing every env values
- terraformValues: A command printing lambdas informations for Terraform
# Provided by \\"@whook/aws-lambda\\": 3 commands
- testConsumerLambda: A command for testing AWS consumer lambda
- testCronLambda: A command for testing AWS cron lambda
- testHTTPLambda: A command for testing AWS HTTP lambda
# Provided by \\"@whook/cli\\": 6 commands
Expand All @@ -38,10 +45,10 @@ Object {
- ls: Print available commands
# Provided by \\"@whook/whook\\": none
# Provided by \\"@whook/cors\\": none
# Provided by \\"@whook/cors\\": none
# Provided by \\"@whook/whook\\": none
",
}
`;

0 comments on commit b730dc9

Please sign in to comment.