Skip to content

Commit

Permalink
Merge pull request #4583 from jeffnoehren/master
Browse files Browse the repository at this point in the history
Spotinst - adding Java8 template and updating docs
  • Loading branch information
horike37 committed Jan 4, 2018
2 parents 92c16ab + 4fbd0cc commit c639e30
Show file tree
Hide file tree
Showing 28 changed files with 703 additions and 30 deletions.
4 changes: 4 additions & 0 deletions docker-compose.yml
Expand Up @@ -87,6 +87,10 @@ services:
image: ruby2.4.1
volumes:
- ./tmp/serverless-integration-test-spotinst-ruby:/app
spotinst-java8:
image: maven:3-jdk-8
volumes:
- ./tmp/serverless-integration-test-spotinst-java8:/app
webtasks-nodejs:
image: node:6.10.3
volumes:
Expand Down
6 changes: 5 additions & 1 deletion docs/providers/spotinst/README.md
Expand Up @@ -29,7 +29,10 @@ If you have questions, join the [chat in gitter](https://gitter.im/serverless/se
<li><a href="./guide/credentials.md">Credentials</a></li>
<li><a href="./guide/serverless.yml.md">Serverless.yml Reference</a></li>
<li><a href="./guide/variables.md">Variables</a></li>
<li><a href="./guide/document-store.md">Document Store</a></li>
<li><a href="./guide/document-store.md">Document Store API</a></li>
<li><a href="./guide/document-store-sdk.md">Document Store SDK</a></li>
<li><a href="./guide/endpoint-setup.md">Endpoint Set Up</a></li>
<li><a href="./guide/endpoint-api.md">Endpoint API Documentation</a></li>
</ul>
</div>
</div>
Expand All @@ -48,6 +51,7 @@ If you have questions, join the [chat in gitter](https://gitter.im/serverless/se
<li><a href="./cli-reference/deploy-function.md">Deploy Function</a></li>
<li><a href="./cli-reference/invoke.md">Invoke</a></li>
<li><a href="./cli-reference/logs.md">Logs</a></li>
<li><a href="./cli-reference/stage.md">Stage Variable</a></li>
<li><a href="./cli-reference/info.md">Info</a></li>
<li><a href="./cli-reference/remove.md">Remove</a></li>
<li><a href="./cli-reference/plugin-list.md">Plugin List</a></li>
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/spotinst/cli-reference/info.md
@@ -1,7 +1,7 @@
<!--
title: Serverless Framework Commands - Spotinst Functions - Info
menuText: info
menuOrder: 7
menuOrder: 8
description: Display information about your deployed service and the Webtask Functions, Events.
layout: Doc
-->
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/spotinst/cli-reference/plugin-list.md
@@ -1,7 +1,7 @@
<!--
title: Serverless Framework Commands - Spotinst Functions - Plugin List
menuText: Plugin List
menuOrder: 9
menuOrder: 10
description: List all available Serverless plugins
layout: Doc
-->
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/spotinst/cli-reference/plugin-search.md
@@ -1,7 +1,7 @@
<!--
title: Serverless Framework Commands - Spotinst Functions - Plugin Search
menuText: Plugin Search
menuOrder: 10
menuOrder: 11
description: Search through all available Serverless plugins
layout: Doc
-->
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/spotinst/cli-reference/plugin-uninstall.md
@@ -1,7 +1,7 @@
<!--
title: Serverless Framework Commands - Spotinst Functions - Plugin Uninstall
menuText: Plugin Uninstall
menuOrder: 12
menuOrder: 13
description: Uninstall a Serverless plugin
layout: Doc
-->
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/spotinst/cli-reference/remove.md
@@ -1,7 +1,7 @@
<!--
title: Serverless Framework Commands - Spotinst Functions - Remove
menuText: remove
menuOrder: 8
menuOrder: 9
description: Remove a deployed Service and all of its Spotinst Functions Functions, Events and Resources
layout: Doc
-->
Expand Down
35 changes: 35 additions & 0 deletions docs/providers/spotinst/cli-reference/stage.md
@@ -0,0 +1,35 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Stage Variables
menuText: Stage Variables
menuOrder: 7
description: How to use the Stage Variables feature
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/credentials)
<!-- DOCS-SITE-LINK:END -->

# Spotinst Functions - Stage Variables

You are able to set a stage variable in your function to distinguish between the multiple stages that your function maybe going through. The function is initially set to 'dev' for development but there are two ways you can change the stage if you so need.

## Through Serverless Framwork
To change the stage through the serverless framework you simply need to enter the command

```bash
serverless deploy --stage #{Your Stage Name}
```

## Through the .yml File

To change the stage in the serverless.yml file you need to add the following into the provider tag then deploy your function as usual

```bash
provider:
name: spotinst
stage: #{Your Stage Name}
spotinst:
environment: #{Your Environment ID}
```

1 change: 1 addition & 0 deletions docs/providers/spotinst/examples/README.md
Expand Up @@ -17,3 +17,4 @@ Pick your language of choice:
* [JavaScript](./node)
* [Python](./python)
* [Ruby](./ruby)
* [Java8](./java8)
45 changes: 45 additions & 0 deletions docs/providers/spotinst/examples/java8/README.md
@@ -0,0 +1,45 @@
<!--
title: Hello World Javas8 Example
menuText: Hello World Java8 Example
description: Create a Java8 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/)
<!-- DOCS-SITE-LINK:END -->

# Hello World Java8 Example

Make sure `serverless` is installed.

## 1. Create a service
`serverless create --template spotinst-java8 --path serviceName` `serviceName` is going to be a new directory there the Java8 template will be loaded. Once the download is complete change into that directory. Next you will need to install the Spotinst Serverless Functions plugin by running `npm install` in the root directory. You will need to go into the serverless.yml file and add in the environment variable that you want to deploy into. Also you need to copy the Service name in the serverless.yml file and paste it into the pom.xlm file under the finalName tag. Next you will have to package the project to create a .jar file. To do this run the command `mvn package`.

## 2. Deploy
```bash
serverless deploy
```

## 3. Invoke deployed function
```bash
serverless invoke --function hello
```

In your terminal window you should see the response

```bash
{"hello":"null"}
```

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`
2 changes: 1 addition & 1 deletion docs/providers/spotinst/examples/node/README.md
Expand Up @@ -14,7 +14,7 @@ layout: Doc
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. Next you will need to install the Spotinst Serverless Functions plugin by running `npm install` in the root directory
`serverless create --template spotinst-nodejs --path serviceName` `serviceName` is going to be a new directory there the JavaScript template will be loaded. Once the download is complete change into that directory. Next you will need to install the Spotinst Serverless Functions plugin by running `npm install` in the root directory. You will need to go into the serverless.yml file and add in the environment variable that you want to deploy into.

## 2. Deploy
```bash
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/spotinst/examples/python/README.md
Expand Up @@ -14,7 +14,7 @@ layout: Doc
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. Next you will need to install the Spotinst Serverless Functions plugin by running `npm install` in the root directory
`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. Next you will need to install the Spotinst Serverless Functions plugin by running `npm install` in the root directory. You will need to go into the serverless.yml file and add in the environment variable that you want to deploy into.


## 2. Deploy
Expand Down
2 changes: 1 addition & 1 deletion docs/providers/spotinst/examples/ruby/README.md
Expand Up @@ -14,7 +14,7 @@ layout: Doc
Make sure `serverless` is installed.

## 1. Create a service
`serverless create --template spotinst-ruby --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. Next you will need to install the Spotinst Serverless Functions plugin by running `npm install` in the root directory
`serverless create --template spotinst-ruby --path serviceName` `serviceName` is going to be a new directory there the Ruby template will be loaded. Once the download is complete change into that directory. Next you will need to install the Spotinst Serverless Functions plugin by running `npm install` in the root directory. You will need to go into the serverless.yml file and add in the environment variable that you want to deploy into.


## 2. Deploy
Expand Down
72 changes: 72 additions & 0 deletions docs/providers/spotinst/guide/document-store-sdk.md
@@ -0,0 +1,72 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Document Store SDK
menuText: Document Store SDK
menuOrder: 7
description: How to use the Document Store SDK feature
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/document-store-sdk)
<!-- DOCS-SITE-LINK:END -->

# Spotinst Functions - Document Store SDK

We have encapsulated the Document Store API calls for retrieving your documents so you will not have to make an API call within the given function. This will allow for you as the user to access your documents using thegetDoc/get_doc method located in the context variable. Additionally this will also eliminate the need for authentication within the function for accessing your documents.

## Node
```basg
module.exports.main = (event, context, callback) => {
context.getDoc("myKey", function(err, res) {
if(res) {
console.log('res: ' + res); //myValue
var body = {
res: res
};
callback(null, {
statusCode: 200,
body: JSON.stringify(body),
headers: {"Content-Type": "application/json"}
});
}
});
}
```

## Python
```bash
def main(event, context):
print ('context: %s' % context)

doc = context.get_doc('myKey')
print(doc) #myValue

res = {
'statusCode': 200,
'body': 'res: %s' % doc,
'headers': {"Content-Type": "application/json"}
}
return res
```

## Java 8
```bash
public class Java8Template implements RequestHandler {
@Override
public Response handleRequest(Request request, Context context) {
String value = context.getDoc("myKey");
System.out.println(value); //myValue

Response response = new Response(200, String.format("value: %s", value));

Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");

response.setHeaders(headers);

return response;
}
}
```

0 comments on commit c639e30

Please sign in to comment.