Skip to content

Latest commit

 

History

History
168 lines (111 loc) · 5.42 KB

getting-started.md

File metadata and controls

168 lines (111 loc) · 5.42 KB

Get started with Serverless Framework Open Source & AWS

Getting started with Serverless Framework’s Open Source CLI and AWS only takes a few minutes.

Installation

Install the serverless CLI via NPM:

npm install -g serverless

Note: If you don’t already have Node on your machine, install it first. We suggest using the latest LTS version of NodeJS.

If you don't want to install Node or NPM, you can install a standalone binary.

Install as a standalone binary

MacOS/Linux

To install the latest version, run this command in your terminal:

curl -o- -L https://slss.io/install | bash

To install a specific version, you may set a VERSION variable, for example:

curl -o- -L https://slss.io/install | VERSION=2.72.2 bash

Then, open another terminal window to run the serverless program.

Windows

Install with Chocolatey:

choco install serverless

Upgrade

If serverless was installed via NPM, you can upgrade it via:

npm install -g serverless

# You can also specify a major version:
npm install -g serverless@2

If you installed serverless as a standalone binary, read the following section instead.

Standalone binary

On MacOS/Linux, you can upgrade the standalone serverless binary by running:

serverless upgrade

# You can also restrict the upgrade to the latest v2 version:
curl -o- -L https://slss.io/install | VERSION=2.72.2 bash

On Windows, run:

choco upgrade serverless

Getting started

Run the command below and follow the prompts:

# Create a new serverless project
serverless

# Move into the newly created directory
cd your-service-name

The serverless command will guide you to create a new project, configure your AWS credentials, and optionally set up a free Serverless Dashboard account to monitor, troubleshoot, and test your new service.

Note: Users in China are presented with a setup centered around the chinese Tencent provider. If you are based in China and prefer to use AWS, set the following environment variable: SERVERLESS_PLATFORM_VENDOR=aws.

The newly created project should contain a serverless.yml file. This file defines everything that should be deployed to AWS: functions, events, resources and more. You can learn more about this in the Core Concepts documentation.

If the templates proposed by the serverless command do not fit your needs, you can also explore the project examples from Serverless Inc. and our community. You can install any example with the create command:

# replace folder-name below with the folder name of the example you want to use
$ serverless create \
  -u https://github.com/serverless/examples/tree/master/folder-name \
  -n my-project

Deploying

If you haven't done so already within the serverless command, you can deploy the project at any time by running:

serverless deploy

The deployed functions, resources and URLs will be displayed in the command output.

Invoking function

If you deployed an API, query its URL to trigger the associated Lambda function. You can find that URL in the serverless deploy output, or retrieve it later via serverless info.

If you deployed a function that isn't exposed via a URL, you can invoke it via:

serverless invoke -f hello

# Invoke and display logs:
serverless invoke -f hello --log

Fetching function logs

All logs generated by a function's invocation are automatically stored in AWS CloudWatch. Retrieve those logs in the CLI via:

serverless logs -f hello

# Tail logs
serverless logs -f hello --tail

Monitoring

You can monitor and debug Lambda functions and APIs via the Serverless Dashboard.

To set up Serverless Dashboard, create a free account and run the following command in your project:

serverless

Remove your service

To delete your service, run serverless remove. This will delete all the AWS resources created by your project and ensure that you don't incur any unexpected charges. It will also remove the service from Serverless Dashboard.

serverless remove