From f636f4f73676a220d6d32e68007a45f2d50f60ab Mon Sep 17 00:00:00 2001 From: jeffnoehren Date: Tue, 3 Oct 2017 17:07:24 -0700 Subject: [PATCH] added permissions to the guide, created hello world examples, updated main readme --- docs/providers/spotinst/README.md | 9 ++-- docs/providers/spotinst/events/schedule.md | 24 ++++++++++ docs/providers/spotinst/examples/README.md | 18 ++++++++ .../spotinst/examples/node/README.md | 45 +++++++++++++++++++ .../spotinst/examples/node/handler.js | 25 +++++++++++ .../spotinst/examples/node/package.json | 13 ++++++ .../spotinst/examples/node/serverless.yml | 31 +++++++++++++ .../spotinst/examples/python/README.md | 45 +++++++++++++++++++ .../spotinst/examples/python/handler.py | 14 ++++++ .../spotinst/examples/python/package.json | 13 ++++++ .../spotinst/examples/python/serverless.yml | 31 +++++++++++++ docs/providers/spotinst/guide/permissions.md | 24 ++++++++++ 12 files changed, 288 insertions(+), 4 deletions(-) create mode 100644 docs/providers/spotinst/examples/README.md create mode 100644 docs/providers/spotinst/examples/node/README.md create mode 100644 docs/providers/spotinst/examples/node/handler.js create mode 100644 docs/providers/spotinst/examples/node/package.json create mode 100644 docs/providers/spotinst/examples/node/serverless.yml create mode 100644 docs/providers/spotinst/examples/python/README.md create mode 100644 docs/providers/spotinst/examples/python/handler.py create mode 100644 docs/providers/spotinst/examples/python/package.json create mode 100644 docs/providers/spotinst/examples/python/serverless.yml diff --git a/docs/providers/spotinst/README.md b/docs/providers/spotinst/README.md index 0f6cb3497..832e47a89 100755 --- a/docs/providers/spotinst/README.md +++ b/docs/providers/spotinst/README.md @@ -1,6 +1,6 @@ @@ -25,6 +25,7 @@ If you have questions, join the [chat in gitter](https://gitter.im/serverless/se @@ -71,13 +72,13 @@ If you have questions, join the [chat in gitter](https://gitter.im/serverless/se
diff --git a/docs/providers/spotinst/events/schedule.md b/docs/providers/spotinst/events/schedule.md index 6c8c5511b..7dd5d49f7 100755 --- a/docs/providers/spotinst/events/schedule.md +++ b/docs/providers/spotinst/events/schedule.md @@ -27,3 +27,27 @@ functions: - schedule: rate(2 hours) - schedule: cron(0 12 * * ? *) ``` + + +## Active Status + +You also have the option to set your functions active status as either true or false + +**Note** `schedule` events active status are set to true by default + +This example will create and attach a schedule event for the function `crawl` which is active status is set to `false`. If the status is changed to true the `crawl` function will be called every 10 minutes. + +```yml +functions: + crawl: + handler: crawl + events: + - schedule: + rate: rate(10 minutes) + active: false + +``` + + +## Value + diff --git a/docs/providers/spotinst/examples/README.md b/docs/providers/spotinst/examples/README.md new file mode 100644 index 000000000..1767a48b1 --- /dev/null +++ b/docs/providers/spotinst/examples/README.md @@ -0,0 +1,18 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/aws/examples/hello-world/) + + +# Hello World Serverless Example + +Pick your language of choice: + +* [JavaScript](./node) +* [Python](./python) + diff --git a/docs/providers/spotinst/examples/node/README.md b/docs/providers/spotinst/examples/node/README.md new file mode 100644 index 000000000..40b59a494 --- /dev/null +++ b/docs/providers/spotinst/examples/node/README.md @@ -0,0 +1,45 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/spotinst/node) + + +# Hello World JavaScript Example + +Make sure `serverless` is installed. + +## 1. Create a service +`serverless create --template spotinst-nodejs --path serviceName` `serviceName` is going to be a new directory there the python template will be loaded. Once the download is complete change into that directory + +## 2. Deploy +`serverless deploy` + +## 3. Invoke deployed function +`serverless invoke --function hello` + +In your terminal window you should see the response + +```bash +{ +Deploy functions: +hello: created +Service Information +service: spotinst-python +functions: + hello +} +``` + +Congrats you have just deployed and ran your Hello World function! + +## Short Hand Guide + +`sls` is short hand for serverless cli commands +`-f` is short hand for `--function` +`-t` is short hand for `--template` +`-p` is short hang for `--path` \ No newline at end of file diff --git a/docs/providers/spotinst/examples/node/handler.js b/docs/providers/spotinst/examples/node/handler.js new file mode 100644 index 000000000..56ada204c --- /dev/null +++ b/docs/providers/spotinst/examples/node/handler.js @@ -0,0 +1,25 @@ +/* + * + * Implement your function here. + * The function will get the request as a parameter with query/body properties: + * var queryparams = req.query; + * var body = req.body; + * + * The function should return a Promise that resolves with the following structure: + * resolve({ + * statusCode: 200, + * body: '{"hello":"from NodeJS4.8 function"}', + * headers: {"Content-Type": "application/json"} + * }) + * + */ + +exports.main = function main (req, res) { + // The function should return a Promise. + return new Promise(function(resolve, reject){ + return resolve({ + statusCode: 200, + body: `hello ${req.query.name || "world"}!` + }); + }); +}; diff --git a/docs/providers/spotinst/examples/node/package.json b/docs/providers/spotinst/examples/node/package.json new file mode 100644 index 000000000..ccfcb802d --- /dev/null +++ b/docs/providers/spotinst/examples/node/package.json @@ -0,0 +1,13 @@ +{ + "name": "spotionst-nodejs", + "version": "1.0.0", + "description": "Spotinst Functions NodeJS sample for serverless framework service.", + "main": "handler.js", + "keywords": [ + "serverless", + "spotinst" + ], + "dependencies": { + "serverless-spotinst-functions": "*" + } +} diff --git a/docs/providers/spotinst/examples/node/serverless.yml b/docs/providers/spotinst/examples/node/serverless.yml new file mode 100644 index 000000000..5b6231275 --- /dev/null +++ b/docs/providers/spotinst/examples/node/serverless.yml @@ -0,0 +1,31 @@ +# Welcome to Serverless! +# +# This file is the main config file for your service. +# It's very minimal at this point and uses default values. +# You can always add more config options for more control. +# We've included some commented out config examples here. +# Just uncomment any of them to get that config option. +# +# For full config options, check the docs: +# docs.serverless.com +# +# Happy Coding! + +service: spotinst-nodejs # NOTE: update this with your service name + +provider: + name: spotinst + spotinst: + #environment: # NOTE: Remember to add the environment ID + +functions: + hello: + runtime: nodejs4.8 + handler: handler.main + memory: 128 + timeout: 30 + +# extend the framework using plugins listed here: +# https://github.com/serverless/plugins +plugins: + - serverless-spotinst-functions diff --git a/docs/providers/spotinst/examples/python/README.md b/docs/providers/spotinst/examples/python/README.md new file mode 100644 index 000000000..d716b56ed --- /dev/null +++ b/docs/providers/spotinst/examples/python/README.md @@ -0,0 +1,45 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/spotinst/examples/python/) + + +# Hello World Python Example + +Make sure `serverless` is installed. + +## 1. Create a service +`serverless create --template spotinst-python --path serviceName` `serviceName` is going to be a new directory there the python template will be loaded. Once the download is complete change into that directory + +## 2. Deploy +`serverless deploy` + +## 3. Invoke deployed function +`serverless invoke --function hello` + +In your terminal window you should see the response + +```bash +{ +Deploy functions: +hello: created +Service Information +service: spotinst-python +functions: + hello +} +``` + +Congrats you have just deployed and ran your Hello World function! + +## Short Hand Guide + +`sls` is short hand for serverless cli commands +`-f` is short hand for `--function` +`-t` is short hand for `--template` +`-p` is short hang for `--path` \ No newline at end of file diff --git a/docs/providers/spotinst/examples/python/handler.py b/docs/providers/spotinst/examples/python/handler.py new file mode 100644 index 000000000..9b6df147f --- /dev/null +++ b/docs/providers/spotinst/examples/python/handler.py @@ -0,0 +1,14 @@ +# Implement your function here. +# The function will get the request as parameter. +# The function should return an object + + +def main(args): + queryparams = args.get("query", {}) + body = args.get("body", {}) + + return { + 'statusCode': 200, + 'body': '{"hello":"from Python2.7 function"}', + 'headers': {"Content-Type": "application/json"} + } diff --git a/docs/providers/spotinst/examples/python/package.json b/docs/providers/spotinst/examples/python/package.json new file mode 100644 index 000000000..a7aed6929 --- /dev/null +++ b/docs/providers/spotinst/examples/python/package.json @@ -0,0 +1,13 @@ +{ + "name": "spotionst-python", + "version": "1.0.0", + "description": "Spotinst Functions Python sample for serverless framework service.", + "main": "handler.js", + "keywords": [ + "serverless", + "spotinst" + ], + "dependencies": { + "serverless-spotinst-functions": "*" + } +} diff --git a/docs/providers/spotinst/examples/python/serverless.yml b/docs/providers/spotinst/examples/python/serverless.yml new file mode 100644 index 000000000..58cd69d69 --- /dev/null +++ b/docs/providers/spotinst/examples/python/serverless.yml @@ -0,0 +1,31 @@ +# Welcome to Serverless! +# +# This file is the main config file for your service. +# It's very minimal at this point and uses default values. +# You can always add more config options for more control. +# We've included some commented out config examples here. +# Just uncomment any of them to get that config option. +# +# For full config options, check the docs: +# docs.serverless.com +# +# Happy Coding! + +service: spotinst-python # NOTE: update this with your service name + +provider: + name: spotinst + spotinst: + #environment: # NOTE: Remember to add the environment ID + +functions: + hello: + runtime: python2.7 + handler: handler.main + memory: 128 + timeout: 30 + +# extend the framework using plugins listed here: +# https://github.com/serverless/plugins +plugins: + - serverless-spotinst-functions diff --git a/docs/providers/spotinst/guide/permissions.md b/docs/providers/spotinst/guide/permissions.md index e69de29bb..0c01ea1d9 100644 --- a/docs/providers/spotinst/guide/permissions.md +++ b/docs/providers/spotinst/guide/permissions.md @@ -0,0 +1,24 @@ + + + +### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/spotinst/guide/intro) + + +# Spotinst - Permissions + +Serverless functions can have to optional access permissions to either public or private. A public function is accessable from anywhere, while private access can only be triggered by authorized machines. + +The following is an example of how a private function would be set up in the serverless.yml file + +``` + functions: + hello: + handler: heandler.main + access: private +```