added permissions to the guide, created hello world examples, updated main readme

This commit is contained in:
jeffnoehren 2017-10-03 17:07:24 -07:00
parent 5c426ecf6e
commit f636f4f736
12 changed files with 288 additions and 4 deletions

View File

@ -1,6 +1,6 @@
<!--
title: Serverless - AWS Documentation
menuText: AWS
title: Serverless - Spotinst Documentation
menuText: Spotinst
layout: Doc
-->
@ -25,6 +25,7 @@ If you have questions, join the [chat in gitter](https://gitter.im/serverless/se
<ul>
<li><a href="./guide/intro.md">Intro</a></li>
<li><a href="./guide/quick-start.md">Quick Start</a></li>
<li><a href="./guide/permissions">Permissions</a></li>
<li><a href="./guide/credentials.md">Credentials</a></li>
</ul>
</div>
@ -71,13 +72,13 @@ If you have questions, join the [chat in gitter](https://gitter.im/serverless/se
<div class="docsSection">
<div class="docsSectionHeader">
<a href="./examples/">
<img src="https://s3-us-west-2.amazonaws.com/assets.site.serverless.com/images/sls_aws_examples.png" alt="Serverless Framework AWS Lambda Examples" width="250" draggable="false"/>
<img src="https://spotinst.com/app/uploads/2016/10/spotinst-logo-lightBlue.svg" alt="Serverless Spotinst Examples" width="250" draggable="false"/>
</a>
</div>
<div>
<div>
<ul>
<li><a href="./examples/hello-world">Hello World</a></li>
<li><a href="./examples/">Hello World</a></li>
</ul>
</div>
</div>

View File

@ -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

View File

@ -0,0 +1,18 @@
<!--
title: Hello World Example
menuText: Hello World Example
description: Example of creating a Hello World function in Node.js and Python with the Serverless framework
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/aws/examples/hello-world/)
<!-- DOCS-SITE-LINK:END -->
# Hello World Serverless Example
Pick your language of choice:
* [JavaScript](./node)
* [Python](./python)

View File

@ -0,0 +1,45 @@
<!--
title: Hello World Javascript Example
menuText: Hello World JavaScript Example
description: Create a JavaScript Hello World function
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/spotinst/node)
<!-- DOCS-SITE-LINK:END -->
# 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`

View File

@ -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"}!`
});
});
};

View File

@ -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": "*"
}
}

View File

@ -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: <env-XXXX> # 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

View File

@ -0,0 +1,45 @@
<!--
title: Hello World Python Example
menuText: Hello World Python Example
description: Create a Python Hello World function
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/spotinst/examples/python/)
<!-- DOCS-SITE-LINK:END -->
# 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`

View File

@ -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"}
}

View File

@ -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": "*"
}
}

View File

@ -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: <env-XXXX> # 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

View File

@ -0,0 +1,24 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Introduction
menuText: Intro
menuOrder: 1
description: An introduction to using Spotinst Functions with the Serverless Framework.
layout: Doc
-->
<!-- DOCS-SITE-LINK:START automatically generated -->
### [Read this on the main serverless docs site](https://www.serverless.com/framework/docs/providers/spotinst/guide/intro)
<!-- DOCS-SITE-LINK:END -->
# 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
```