User Guide

Have questions?

Head over to the forums to search for your questions and issues or post a new one.

Edit on github

#Spotinst - Quick Start

Here is a quick guide on how to create a new serverless project using the Spotinst NodeJS template. For more detailed instruction please check out the other reference material provided.

#Install Serverless Framework

First you will need to have the serverless framework installed. To do this you will have to run the command:

npm install -g serverless

#Set Up Credentials

To set up your Spotinst Credentials you will have to have the Spotinst Serverless Plugin installed inside a new Serverless project. The first thing you will need to do is create a new template project and enter the new project directory by entering into the terminal:

serverless create --template spotinst-nodejs --path new-service
cd new-service

Once you are in the project directory you will have to install the plugin but entering:

npm install

After the installation is completed you can then configure your credentials. Before you do this you will want to have your Spotinst account ID number and Spotinst API token ready to go. Those both can be found in the Spotinst Console under settings. Once you have those you will enter:

serverless config credentials --provider spotinst --token {Your Spotinst API Token} --account {Your Spotinst Account ID}

To check to see that your credentials have been set up properly you can check the credentials files by entering:

cat ~/.spotinst/credentials

Here you should see the account ID and Token that are linked to your account.

Note: Once you have set up your Spotinst Credentials you will not need to do this again for each project

For more help please refer to the Credentials link provided

#Create a New Project From a Template

You can skip this step if you have already done this step in configuring your credentials

Create a new service using the Node.js template, specifying a unique name and an optional path for your service.

serverless create --template spotinst-nodejs --path new-service
cd new-service

#Install Spotinst Serverless Functions Plugin

You can skip this step if you have already done this step in configuring your credentials

You will first need to install the Spotinst Functions plugin before you are able to deploy your function. Once this has been done you do not need to do it again for this project.

npm install

#Deploying and Updating the Function

Deploying a project is how you launch the project into production. Once it has been deployed, you will be able to see and edit it in the Spotinst Console.

Before you deploy you will need to add in the environement ID into the serverless.yml file. The environment ID can be found on the Spotinst console under Functions. In this menu you will be able to add applications, environments and functions. An application is able to hold many environments and enivronments can hold many functions. They are mostly used for organization purposes and are at your descretion to manipulate as you like. To deploy your function you will need to select an application and environment and copy/paste the environment ID into the serverless.yml file under the environement tag.

  1. Deploying the Service

Use this when you have made changes to your Functions, Events or Resources in serverless.yml or you simply want to deploy all changes within your Service at the same time.

serverless deploy 
  1. Deploy the Function

Use this to quickly upload and overwrite your function code, allowing you to develop faster.

serverless deploy function -f hello
  1. Updating the Function

Use this to update your function after you have made updates that you want to push to production.

serverless deploy 

#Invoke the Function

Invoking a function simply means to run it. There are many event triggers that will invoke a function depending on your needs. All functions are assigned a unique URL that is initially set to private in the serverless.yml file but if set to public can trigger an invocation from a web browser. Also you are able to set up a cron function in the serverless.yml file to run at regular intervals and invoke the function on a timer. If you simply want to test the function you can invoke from the console. Under the function name there is a Test tab you can select and run a test. Otherwise you are able to test from the terminal as shown below.

Invokes a Function

serverless invoke -f hello

#Cleanup

If at any point, you no longer need your service, you can run the following command to remove the Functions, Events and Resources that were created, and ensure that you don't incur any unexpected charges.

serverless remove