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 May 19, 2020
1 parent 21adf4d commit 79f70b3
Show file tree
Hide file tree
Showing 23 changed files with 4,875 additions and 14 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 @@ -182,6 +182,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 @@ -213,6 +214,7 @@ Mr Bean
"@typescript-eslint/parser": "^2.33.0",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-knifecycle": "^1.2.0",
"eslint": "^7.0.0",
"eslint-plugin-prettier": "^3.1.3",
Expand All @@ -222,6 +224,7 @@ Mr Bean
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"typescript": "^3.9.2",
"webpack": "4.41.5",
},
"engines": Object {
"node": ">=10.19.0",
Expand Down Expand Up @@ -445,6 +448,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 @@ -476,6 +480,7 @@ Mr Bean
"@typescript-eslint/parser": "^2.33.0",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-knifecycle": "^1.2.0",
"eslint": "^7.0.0",
"eslint-plugin-prettier": "^3.1.3",
Expand All @@ -485,6 +490,7 @@ Mr Bean
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"typescript": "^3.9.2",
"webpack": "4.41.5",
},
"engines": Object {
"node": ">=10.19.0",
Expand Down Expand Up @@ -693,6 +699,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 @@ -724,6 +731,7 @@ Mr Bean
"@typescript-eslint/parser": "^2.33.0",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-knifecycle": "^1.2.0",
"eslint": "^7.0.0",
"eslint-plugin-prettier": "^3.1.3",
Expand All @@ -733,6 +741,7 @@ Mr Bean
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"typescript": "^3.9.2",
"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

0 comments on commit 79f70b3

Please sign in to comment.