Skip to content

Commit

Permalink
Spotinst - Adding docs for new Endpoint Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffnoehren committed Dec 22, 2017
1 parent 3158c4c commit 189cddc
Show file tree
Hide file tree
Showing 9 changed files with 298 additions and 9 deletions.
4 changes: 3 additions & 1 deletion docs/providers/spotinst/README.md
Expand Up @@ -30,7 +30,8 @@ If you have questions, join the [chat in gitter](https://gitter.im/serverless/se
<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/stage.md">Stage Variable</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 @@ -49,6 +50,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
@@ -1,7 +1,7 @@
<!--
title: Serverless Framework - Spotinst Functions Guide - Stage Variables
menuText: Stage Variables
menuOrder: 8
menuOrder: 7
description: How to use the Stage Variables feature
layout: Doc
-->
Expand All @@ -18,7 +18,7 @@ You are able to set a stage variable in your function to distinguish between the
To change the stage through the serverless framework you simply need to enter the command

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

## Through the .yml File
Expand All @@ -28,7 +28,7 @@ To change the stage in the serverless.yml file you need to add the following int
```bash
provider:
name: spotinst
stage: #{Your Stage Name}
stage: #{Your Stage Name}
spotinst:
environment: #{Your Environment ID}
```
Expand Down
202 changes: 202 additions & 0 deletions docs/providers/spotinst/guide/endpoint-api.md
@@ -0,0 +1,202 @@
<!--
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
```
85 changes: 85 additions & 0 deletions docs/providers/spotinst/guide/endpoint-setup.md
@@ -0,0 +1,85 @@
<!--
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)

0 comments on commit 189cddc

Please sign in to comment.