Getting started with Serverless Framework’s Open Source CLI and AWS only takes a few minutes.
Install the serverless CLI via NPM:
npm install -g serverlessNote: 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.
To install the latest version, run this command in your terminal:
curl -o- -L https://slss.io/install | bashTo install a specific version, you may set a VERSION variable, for example:
curl -o- -L https://slss.io/install | VERSION=2.72.2 bashThen, open another terminal window to run the serverless program.
Install with Chocolatey:
choco install serverlessIf serverless was installed via NPM, upgrade it via:
npm install -g serverless
# You can also specify a major version:
npm install -g serverless@2If you installed serverless as a standalone binary, read the following section instead.
On MacOS/Linux, run:
serverless upgrade
# You can also restrict the upgrade to the latest v2 version:
curl -o- -L https://slss.io/install | VERSION=2.72.2 bashOn Windows, run:
choco upgrade serverlessRun the command below and follow the prompts:
# Create a new serverless project
serverless
# Move into the newly created directory
cd your-service-nameThe 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-projectIf you haven't done so already within the serverless command, you can deploy the project at any time by running:
serverless deployThe deployed functions, resources and URLs will be displayed in the command output.
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 --logAll 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 --tailYou 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:
serverlessTo 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