From 196d5ad3f0b2d0e94e572cde83ecb15c3ed98cd0 Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Tue, 12 Mar 2019 10:38:18 -0700 Subject: [PATCH 1/5] add example using lambda-wrapper --- lambda-wrapper/.gitignore | 6 ++++++ lambda-wrapper/README.md | 16 ++++++++++++++++ lambda-wrapper/binaris.d.ts | 31 +++++++++++++++++++++++++++++++ lambda-wrapper/binaris.yml | 9 +++++++++ lambda-wrapper/function.js | 5 +++++ lambda-wrapper/handler.js | 5 +++++ lambda-wrapper/package.json | 30 ++++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+) create mode 100644 lambda-wrapper/.gitignore create mode 100644 lambda-wrapper/README.md create mode 100644 lambda-wrapper/binaris.d.ts create mode 100644 lambda-wrapper/binaris.yml create mode 100644 lambda-wrapper/function.js create mode 100644 lambda-wrapper/handler.js create mode 100644 lambda-wrapper/package.json diff --git a/lambda-wrapper/.gitignore b/lambda-wrapper/.gitignore new file mode 100644 index 0000000..2b48c8b --- /dev/null +++ b/lambda-wrapper/.gitignore @@ -0,0 +1,6 @@ +# package directories +node_modules +jspm_packages + +# Serverless directories +.serverless \ No newline at end of file diff --git a/lambda-wrapper/README.md b/lambda-wrapper/README.md new file mode 100644 index 0000000..6eb6b51 --- /dev/null +++ b/lambda-wrapper/README.md @@ -0,0 +1,16 @@ +# Lambda wrapper example + +This example demonstrates how to deploy a Binaris function that will run Lambda code. + +### Usage + +```bash +$ npm install +$ bn deploy wrapped_lambda +$ bn invoke wrapped_lambda + "Hello serverless!" +``` + +If you have existing Lambda code you would like to use, simply replace the contents of `handler.js`. + +> Note: If your Lambda code has a different entrypoint, remember to update the `binaris.yml` \ No newline at end of file diff --git a/lambda-wrapper/binaris.d.ts b/lambda-wrapper/binaris.d.ts new file mode 100644 index 0000000..1297026 --- /dev/null +++ b/lambda-wrapper/binaris.d.ts @@ -0,0 +1,31 @@ +/// +interface BinarisHTTPRequest { + env: Record; + query: Record; + body: Buffer; + path: string; + method: string; + requestId: string; + headers: Record; +} + +interface FunctionResponse { + statusCode: number; + headers: Record; + body: Buffer | string; +} + +declare class BinarisHTTPResponse implements FunctionResponse { + userResponse: Partial; + constructor(userResponse: Partial); + statusCode: number; + headers: Record; + body: Buffer | string; +} + +declare type FunctionContext = { + request: BinarisHTTPRequest; + HTTPResponse: typeof BinarisHTTPResponse; +}; + +export declare type BinarisFunction = (body: unknown, context: FunctionContext) => Promise diff --git a/lambda-wrapper/binaris.yml b/lambda-wrapper/binaris.yml new file mode 100644 index 0000000..79d38b5 --- /dev/null +++ b/lambda-wrapper/binaris.yml @@ -0,0 +1,9 @@ +functions: + wrapped_lambda: + file: function.js + entrypoint: handler + executionModel: concurrent + runtime: node8 + env: + LAMBDA_FILE_PATH: 'handler.js' + LAMBDA_HANDLER: 'hello' diff --git a/lambda-wrapper/function.js b/lambda-wrapper/function.js new file mode 100644 index 0000000..8dae19a --- /dev/null +++ b/lambda-wrapper/function.js @@ -0,0 +1,5 @@ +const { wrapLambda } = require('./node_modules/lambda-binaris-wrapper/lib/index.js'); + +const { LAMBDA_FILE_PATH, LAMBDA_HANDLER } = process.env; + +exports.handler = wrapLambda(LAMBDA_FILE_PATH, LAMBDA_HANDLER); diff --git a/lambda-wrapper/handler.js b/lambda-wrapper/handler.js new file mode 100644 index 0000000..ad03eb4 --- /dev/null +++ b/lambda-wrapper/handler.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports.hello = async (event, context) => { + return 'Hello serverless!'; +}; diff --git a/lambda-wrapper/package.json b/lambda-wrapper/package.json new file mode 100644 index 0000000..e930193 --- /dev/null +++ b/lambda-wrapper/package.json @@ -0,0 +1,30 @@ +{ + "name": "lambda-binaris-example", + "version": "1.0.0", + "private": true, + "license": "MIT", + "description": "Invoke existing AWS Lambdas as Binaris functions", + "main": "function.js", + "repository": { + "type": "git", + "url": "git+https://github.com/binaris/functions-examples.git" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "bugs": { + "url": "https://github.com/binaris/functions-examples/issues" + }, + "homepage": "https://github.com/binaris/functions-examples/lambda-binaris/README.md", + "author": "Ryland Goldstein", + "dependencies": { + "@binaris/lambda-binaris-wrapper": "^1.0.0-rc.1" + }, + "keywords": [ + "Binaris", + "Slack", + "FaaS", + "Pi", + "Command" + ] +} From 80511fb99f576d69336e6996711e78c714f0847a Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Tue, 12 Mar 2019 10:39:38 -0700 Subject: [PATCH 2/5] rm generated files --- lambda-wrapper/.gitignore | 6 ------ lambda-wrapper/binaris.d.ts | 31 ------------------------------- 2 files changed, 37 deletions(-) delete mode 100644 lambda-wrapper/.gitignore delete mode 100644 lambda-wrapper/binaris.d.ts diff --git a/lambda-wrapper/.gitignore b/lambda-wrapper/.gitignore deleted file mode 100644 index 2b48c8b..0000000 --- a/lambda-wrapper/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# package directories -node_modules -jspm_packages - -# Serverless directories -.serverless \ No newline at end of file diff --git a/lambda-wrapper/binaris.d.ts b/lambda-wrapper/binaris.d.ts deleted file mode 100644 index 1297026..0000000 --- a/lambda-wrapper/binaris.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -/// -interface BinarisHTTPRequest { - env: Record; - query: Record; - body: Buffer; - path: string; - method: string; - requestId: string; - headers: Record; -} - -interface FunctionResponse { - statusCode: number; - headers: Record; - body: Buffer | string; -} - -declare class BinarisHTTPResponse implements FunctionResponse { - userResponse: Partial; - constructor(userResponse: Partial); - statusCode: number; - headers: Record; - body: Buffer | string; -} - -declare type FunctionContext = { - request: BinarisHTTPRequest; - HTTPResponse: typeof BinarisHTTPResponse; -}; - -export declare type BinarisFunction = (body: unknown, context: FunctionContext) => Promise From 92723e27cfdfe3923d566e9fa950b35c6987ed0f Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Tue, 12 Mar 2019 10:41:23 -0700 Subject: [PATCH 3/5] update package.json --- lambda-wrapper/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lambda-wrapper/package.json b/lambda-wrapper/package.json index e930193..35d1099 100644 --- a/lambda-wrapper/package.json +++ b/lambda-wrapper/package.json @@ -1,5 +1,5 @@ { - "name": "lambda-binaris-example", + "name": "lambda-binaris-wrapper", "version": "1.0.0", "private": true, "license": "MIT", @@ -15,7 +15,7 @@ "bugs": { "url": "https://github.com/binaris/functions-examples/issues" }, - "homepage": "https://github.com/binaris/functions-examples/lambda-binaris/README.md", + "homepage": "https://github.com/binaris/functions-examples/lambda-binaris-wrapper/README.md", "author": "Ryland Goldstein", "dependencies": { "@binaris/lambda-binaris-wrapper": "^1.0.0-rc.1" From e9d212b96e661106ace3401a6cac6d4d856acb12 Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Tue, 12 Mar 2019 10:41:52 -0700 Subject: [PATCH 4/5] rename --- {lambda-wrapper => lambda-binaris-wrapper}/README.md | 0 {lambda-wrapper => lambda-binaris-wrapper}/binaris.yml | 0 {lambda-wrapper => lambda-binaris-wrapper}/function.js | 0 {lambda-wrapper => lambda-binaris-wrapper}/handler.js | 0 {lambda-wrapper => lambda-binaris-wrapper}/package.json | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {lambda-wrapper => lambda-binaris-wrapper}/README.md (100%) rename {lambda-wrapper => lambda-binaris-wrapper}/binaris.yml (100%) rename {lambda-wrapper => lambda-binaris-wrapper}/function.js (100%) rename {lambda-wrapper => lambda-binaris-wrapper}/handler.js (100%) rename {lambda-wrapper => lambda-binaris-wrapper}/package.json (100%) diff --git a/lambda-wrapper/README.md b/lambda-binaris-wrapper/README.md similarity index 100% rename from lambda-wrapper/README.md rename to lambda-binaris-wrapper/README.md diff --git a/lambda-wrapper/binaris.yml b/lambda-binaris-wrapper/binaris.yml similarity index 100% rename from lambda-wrapper/binaris.yml rename to lambda-binaris-wrapper/binaris.yml diff --git a/lambda-wrapper/function.js b/lambda-binaris-wrapper/function.js similarity index 100% rename from lambda-wrapper/function.js rename to lambda-binaris-wrapper/function.js diff --git a/lambda-wrapper/handler.js b/lambda-binaris-wrapper/handler.js similarity index 100% rename from lambda-wrapper/handler.js rename to lambda-binaris-wrapper/handler.js diff --git a/lambda-wrapper/package.json b/lambda-binaris-wrapper/package.json similarity index 100% rename from lambda-wrapper/package.json rename to lambda-binaris-wrapper/package.json From 85e8b87709f160ede9e2c0b6d8bab26f91be5c07 Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Tue, 12 Mar 2019 10:43:09 -0700 Subject: [PATCH 5/5] add to outer README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0b100c5..63af8d6 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,4 @@ Each example contains a README.md with an explanation about the solution and it' | [`five-minute-serverless-backend`](five-minute-serverless-backend)
Build a serverless web backend in 5 minutes | nodeJS | | [`quines`](quines)
A small collection of self-replicating functions | nodeJS and python2 | | [`python-crud-google-spreadsheet`](python-crud-google-spreadsheet)
Google Spreadsheet CRUD with functions | python3 | +| [`lambda-binaris-wrapper`](lambda-binaris-wrapper)
Run AWS Lambda code directly on Binaris | nodeJS |