Spotinst - reformatting docs to be more readable

This commit is contained in:
jeffnoehren 2018-02-07 16:36:20 -08:00
parent 404e780c8c
commit 9b53816716
9 changed files with 38 additions and 542 deletions

View File

@ -29,10 +29,8 @@ 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 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>
<li><a href="./guide/endpoints.md">Endpoints</a></li>
<li><a href="./guide/cors.md">Cross-Origin Resource Sharing</a></li>
<li><a href="./guide/active-versions.md">Active Versions Documentation</a></li>
</ul>
</div>

View File

@ -1,7 +1,7 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Active Versions
menuText: Active Versions
menuOrder: 12
menuOrder: 8
description: How to set which versions to deploy
layout: Doc
-->

View File

@ -1,7 +1,7 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Credentials
menuText: Credentials
menuOrder: 4
menuOrder: 7
description: How to set up the Serverless Framework with your Spotinst Functions credentials
layout: Doc
-->
@ -16,7 +16,7 @@ Cross-Origin Resource Sharing is a mechanism that allows restricted resources on
You can enable CORS for cross-domain HTTP requests with Spotinst Functions. Add the required fields to you serverless.yml file.
Example CORS object:
```yaml
```yml
cors:
- enabled: true
origin: "http://foo.example"

View File

@ -1,72 +0,0 @@
<!--
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;
}
}
```

View File

@ -1,175 +0,0 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Document Store API
menuText: Document Store API
menuOrder: 7
description: How to use the Document Store API 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 - Document Store API
Document Store is a way for you to save information across function calls within the same environment without having to access an external database. It is secured by your Spotinst account credentials and can only be accesses within a function. Because you do not need to access an external database you are able to fetch stored documents with low latency (< ~5ms)
To access the document store you will need to make an API request inside a funciton formatted bellow.
## Add New Value
This is how to insert a new key/value pair into your document store in a specific environment
**HTTPS Request:**
```bash
POST environment/${environmentId}/userDocument?accountId=${accountId}
```
**Host:**
```bash
api.spotinst.io/functions/
```
**Header:**
```bash
{
"Content-Type": "application/json",
"Authorization": "Bearer ${Spotinst API Token}"
}
```
**Body:**
```bash
{
"userDocument" : {
"key": “${Your Key}”,
"value": “${Your Value}”
}
}
```
## Update Value
This is how to update a current key/value pair in your document store in a specific environment
**HTTPS Request:**
```bash
PUT environment/${environmentId}/userDocument/${Key}?accountId=${accountId}
```
**Endpoint:**
```bash
api.spotinst.io/functions/
```
**Header:**
```bash
{
"Content-Type": "application/json",
"Authorization": "Bearer ${Spotinst API Token}"
}
```
**Body:**
```bash
{
"userDocument" : {
"value": “${Your Value}”
}
}
```
## Get Values
There are two ways to get the documents from your store, either by specifing a key which will return both the key and the value or you can just leave this out and you will get all the keys in the environment
### 1. Get Sinlge Key Pair
**HTTPS Request:**
```bash
GET environment/${environmentId}/userDocument/${Key}?accountId=${accountId}
```
**Endpoint:**
```bash
api.spotinst.io/functions/
```
**Header:**
```bash
{
"Content-Type": "application/json",
"Authorization": "Bearer ${Spotinst API Token}"
}
```
### 2. Get All Keys
**HTTPS Request:**
```bash
GET environment/${environmentId}/userDocument?accountId=${accountId}
```
**Endpoint:**
```bash
api.spotinst.io/functions/
```
**Header:**
```bash
{
"Content-Type": "application/json",
"Authorization": "Bearer ${Spotinst API Token}"
}
```
## Delete Value
This is how to delete a specific key value pair from your document store
**HTTPS Request:**
```bash
DELETE environment/${environmentId}/userDocument/${Key}?accountId=${accountId}
```
**Endpoint:**
```bash
https://api.spotinst.io/functions/
```
**Header:**
```bash
{
"Content-Type": "application/json",
"Authorization": "Bearer ${Spotinst API Token}"
}
```
## GitHub
Check out some examples to help you get started!
[Get All Values Function](https://github.com/spotinst/spotinst-functions-examples/tree/master/node-docstore-getAll)
[Insert New Value Function](https://github.com/spotinst/spotinst-functions-examples/tree/master/node-docstore-newValue)

View File

@ -1,202 +0,0 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Endpoint API Documentation
menuText: Endpoint API Documentation
menuOrder: 7
description: How to use the Endpoint API
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 - Endpoint API Documentation
Here is the full list of API calls that you can make to set alias and patterns. Please check out the full article on Setting Up Endpoints first because it will make more sense.
## Alias
### Create Alias
Create a new alias to point to your environment
#### HTTPS Request
```bash
POST alias?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Body
```bash
{
"alias": {
"host": "myAlias.com",
"environmentId": ${Environment ID}
}
}
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
### Get Alias
Returns a single alias
#### HTTPS Request
```bash
GET alias/${Alias ID}?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
### Get All Alias
Returns all the alias in your account
#### HTTPS Request
```bash
GET alias?accountId=${accountId}
```
##### Host
```bash
api.spotinst.io/functions/
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
### Delete Alias
Deletes a single alias
#### HTTPS Request
```bash
DELETE alias/${Alias ID}?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
## Pattern
### Create Pattern
Create a new pattern that maps to a function
#### HTTPS Request
```bash
POST pattern?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Body
```bash
{
"pattern": {
"environmentId":${Environment ID},
"method": "ALL",
"pattern": "/*",
"functionId": ${Function ID}
}
}
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
### Update Pattern
Update and existing pattern
#### HTTPS Request
```bash
PUT pattern/${Pattern ID}?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Body
```bash
{
"pattern": {
"environmentId":${Environment ID},
"method": "ALL",
"pattern": "/*",
"functionId": ${Function ID}
}
}
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
### Get Pattern
Returns a single pattern
#### HTTPS Request
```bash
GET pattern/${Pattern ID}?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
### Get All Patterns
Returns all the patterns your account
#### HTTPS Request
```bash
POST pattern?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
### Delete Pattern
Delete a single pattern
#### HTTPS Request
```bash
DELETE pattern/${Pattern ID}?accountId=${accountId}
```
#### Host
```bash
api.spotinst.io/functions/
```
#### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```

View File

@ -1,85 +0,0 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Endpoint Setup
menuText: Endpoint Set Up
menuOrder: 7
description: How to set up an Endpoint
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 - Endpoint Setup
You are able to set an alias URL name as an endpoint for your serverless function to make it more accessible to your users. The way this works is you will point the domain of your choosing to your environment URL's then you will set paths to each of the functions in that environment you wish to bundle in together. To do this you will first need a valid domain. For this example I will be using 'myAlias.com'.
## Set DNS Record
First you will want to create a DNS record set that will point to your environment URL. Your environment URL can be found in the Spotinst console. When you select the environment you wish to connect you will see a list of functions and their individual URL's. Like this
```bash
https://app-123xyz-raffleapp-execute-function1.spotinst.io/fx-abc987
```
We only want the URL starting at app and ending before the function id. Like this
```bash
app-123xyz-raffleapp-execute-function1.spotinst.io
```
With this you will need to go to a DNS record setter and point your domain to this URL. I used AWS Route 53 to set this up.
## Set Alias
Next you will need to set the alias in your Spotinst environment by making an API call. This does not need to be done within a function and can be set anyway you are most comfortable. The API request is connecting your domain the environment that you want. This is the API request
### HTTPS Request
```bash
POST alias?accountId=${accountId}
```
### Host
```bash
api.spotinst.io/functions/
```
### Body
```bash
{
"alias": {
"host": "myAlias.com",
"environmentId": ${Your Environment ID}
}
}
```
### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
**Note:** You are able to connect multiple alias to the same environment
## Set Up Pattern
After you have an alias set up you will need to set up pattern to connect to all the functions in the application. This is again another API call and can be done from anywhere. You specify the pattern that you want, the method that will trigger the function, the function ID and the environment ID. The pattern is what will appear after the domain. For example '/home' would point to 'myAlias.com/home'. The methods you can select are any of the usual HTTP request methods: GET, PUT, POST, DELETE , OPTIONS, PATCH, ALL where “ALL” matches every method
### HTTPS Request
```bash
POST pattern?accountId=${accountId}
```
### Host
```bash
api.spotinst.io/functions/
```
### Body
``` bash
{
"pattern": {
"environmentId": ${Your Environment ID},
"method": "ALL",
"pattern": "/*",
"functionId": ${Your Function ID}
}
}
```
### Headers
```bash
Authorization: Bearer ${Spotinst API Token}
Content-Type: application/json
```
## API Documentation
The full API documentation has information like delete and get alias and patterns. Check it out [here](./endpoint-api.md)

View File

@ -0,0 +1,32 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Endpoint Setup
menuText: Endpoint Set Up
menuOrder: 6
description: How to set up an Endpoint
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 - Endpoints
You are able to set your custom endpoint path in the serverless.yml file if you do not want to use the console or API. You will have to set up your environment Alias in the console but here you can set the path and method for your individual functions to be mapped to.
Here is a sample function from a yml file. As you can see at the bottom of the file we have listed an endpoint with a path and method. Both of these will need to be set in order to be deployed properly
```yml
hello:
runtime: nodejs8.3
handler: handler.main
memory: 128
timeout: 30
access: public
endpoint:
path: /home
method: get
```
For more information on how to set up endpoint alias and patterns check out our documentation [here](https://help.spotinst.com/hc/en-us/articles/115005893709)

View File

@ -39,7 +39,7 @@ URL parameters can be use when a POST request is made to the endpoint of your fu
### 1. Node JS
To access URL parameters in your NodeJS code you just need to put `event.query.['{Your Parameter Name}']` as needed
To access URL parameters in your NodeJS code you just need to put `event.query['{Your Parameter Name}']` as needed
### 2. Python