1.1.3 • Published 6 years ago

serverless-spotinst-functions v1.1.3

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

Serverless - Spotinst Functions

Spotinst Functions is a Multi-Cloud Functions-as-a-Service (FaaS) platform that utilizes affordable compute and network infrastructure. Spotinst will take care of everything required to run and scale your code with high availabilty across all cloud providers (AWS, Azure, Google Cloud, IBM Cloud, Oracle, and Equinix.)

Functions are independent units of deployment, like microservices. They are code deployed and the cloud written to perform a specific job.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system. For more information, please see the Serverless provider documentation. for Spotinst.

Prerequisites

You will need a Spotinst Account and Spotinst API token to complete setup. Sign up for a Spotinst Account here. You can create your API token by navigating to My Account>API and selecting generate token. Note: You only need to set up your credentials once.

img

img

Installing

First, install the serverless framework.

npm install -g serverless

Next, set up your credentials. You'll need to have the Spotinst Serverless plugin already installed inside a new Serverless project. Create a new template project and specify the directory with --path

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

Install node modules from within the directory (in this example: /new-service)

npm install

If this is your first Functions project, you need to configure your credentials. Enter your Spotinst Account and API token:

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

Double-check that your credentials are properly set up:

cat ./spotinst/credentials

You should see the account ID and token.

Deployment

Deploying a project places it into production and allows you to see and edit it in the Spotinst Console. In order to deploy, you will need to associate the function with an environment in the Spotinst Console. 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 a collection of one or more environments, and an environment is a collection of one or more functions. Use this structure to organize projects in a way that best suits your needs.

Select the application and environment to see the environment ID. Copy-paste this ID into your severless.yml file. Don't forget to change your function name before deploying!

img

service: your-service

provider:
  name: spotinst
  spotinst:
    environment: {environment ID} # ex: env-123456

functions:
  hello:  # this defaults to hello, don't forget to change it!
    runtime: nodejs8.3
    handler: handler.main
    memory: 128
    timeout: 30
    access: private

With that set, you can deploy (and later, update) the service with the same command:

serverless deploy

To deploy/update a single function, use:

serverless deploy -f hello

Invoking the function

You can invoke the function from the Spotinst Console and from the command line. To invoke from the command line, run:

serverless invoke -f hello

To use the Spotinst Console, select the function from within the Application and Environment menu and click 'run test' from the 'Test' tab.

Additionally, if you change the access parameter to 'public' in your function's serverless.yml file, you can invoke your function using the generated HTTP endpoint, found under the 'Triggers' tab in the Console. Also under 'Triggers' is the ability to add a CRON trigger for running the function at a regular interval.

img

Logs

Logs are viewable in the 'Logs' section of each function on the Spotinst Console. There is a small time lag between function invokation and logs appearing in the list.

You can see the logs for a given function from the command line. Use the --startTime option to denote a unit of time.

serverless logs -f hello --StartTime 3h

This command will show you the past 3 hours worth of logs for the function hello.

Cleanup

If you no longer need your service, run the remove command to ensure you don't incur any unexpected charges:

serverless remove
1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago