Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@whook/example): add AWS lambdas build #54

Merged
merged 1 commit into from Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1,178 changes: 260 additions & 918 deletions package-lock.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions packages/whook-create/src/services/createWhook.test.ts
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
58 changes: 58 additions & 0 deletions packages/whook-example/README.md
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