Socket
Book a DemoInstallSign in
Socket

@serverless/cli

Package Overview
Dependencies
Maintainers
7
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serverless/cli

Serverless CLI

npmnpm
Version
0.0.4
Version published
Weekly downloads
60K
-5.74%
Maintainers
7
Weekly downloads
 
Created
Source

Serverless CLI

The Serverless CLI is a lightweight tool for developing, testing and deploying your serverless apps.

Table of Contents

Quick Start

Install the Serverless CLI with the following command:

npm install -g @serverless/cli

Run the CLI with the following command to initialize the Serverless Session:

serverless

Initialize a new app with the init command

init

Just follow the wizard to get started!

See the list of supported commands by running:

help

Setup

Even though you can start using the CLI without setting up your config, the usage will be limited to some commands. To get the full functionality you need to setup your config, specially your provider credentials.

Create a .serverlessrc file in the root of your app that looks like this:

{
  "deployConfig": {
    "regions": [ "us-east-1" ],
    "aws": {
      "accessKeyId": "abc",
      "secretAccessKey": "abc",
      "role": "arn:aws:iam::123:role/abc", => a role that your functions will assume
      "sessionToken": null
    },
    "gateway": {
        "url": "http://localhost:4000",
        "configurationUrl": "http://localhost:4001"
      }
  }
}

This .serverlessrc is gitignored by default. You can also move this deployConfig object into the global configuration in ~/.serverlessrc. This would be used by any app that does not have a local config. You can use the config commands below to make things easier.

Development

Requirements

  • node.js 6.0+
  • npm 3.0+

Clone and Install Dependencies

Clone the repo:

git clone https://github.com/serverless/cli.git

Install dependencies:

npm install

Build & Watch

build/watch the CLI code base with the following command:

npm run watch

Using different stages

Serverless has dev, staging, and production environments

You can change the URLs for login by setting process.env.STAGE to another stage value. Default stage is dev.

export STAGE=staging

Using Example Apps

In another terminal window, navigate to one of the example apps:

cd examples/appA

and run/test the CLI:

serverless

Make sure you add a .serverlessrc file to the example app you're working on with your required config. See the setup section for more info.

Use a local version of the SDK

  • Go to the sdk/sdk folder and run npm install && npm run watch
  • In another terminal in the same sdk/sdk folder run npm link
  • Go to cli folder and run npm link @serverless/sdk then npm run watch
  • In another terminal in the same cli folder run the cli and start testing
  • Now you can run the CLI using node dist/bin.js

Commands

You can either run commands directly prefixed with serverless (for example serverless deploy), or from within a session that you've already run with just the serverless command.

Here's the list of all the supported commands:

Init

sls init

initializes a project & serverless component

template - (t) template to bootstrap your app.

Available templates: aws-nodejs

path - (p) path to place your app in

description - (d) description of your app.

version - (v) version of the app.

Create

sls create

creates an app

template - (t) template to bootstrap your app.

Available templates: aws-nodejs

path - (p) path to place your app in

description - (d) description of your app.

version - (v) version of the app.

Login

sls login

logs into your Serverless Platform account

Logout

sls logout

logs out of your Serverless Platform account

Config

sls config

configures the cli

Config Set

sls config set

adds a config key/value

Config Get

sls config get

gets a config value by key

Config Delete

sls config delete

deletes a config

Pack

sls pack

packages output directory.

outputDir - (o) packages output directory.

Push

sls push

pushes your application

Deploy

sls deploy

deploys your application

Invoke

sls invoke

invokes a function

data - (d) invocation data.

Emit

sls emit

emits an event

data - (d) event data.

Run

sls emit

emits an event

data - (d) event data.

Rollback

sls rollback

rolls back your application to a previous version

Remove

sls remove

removes your application

FAQs

Package last updated on 22 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts