Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4583 from jeffnoehren/master
Spotinst - adding Java8 template and updating docs
- Loading branch information
Showing
28 changed files
with
703 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ Pick your language of choice: | |
* [JavaScript](./node) | ||
* [Python](./python) | ||
* [Ruby](./ruby) | ||
* [Java8](./java8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
``` | ||
|
Oops, something went wrong.