Serverless Framework CLI Reference
The Serverless Framework simplifies deploying and managing serverless applications on AWS Lambda (and other cloud providers). The following commands cover the core workflow.
Installation
npm install -g serverless
Create a new project
# Create from a template (Python on AWS)
sls create --template aws-python --path my-service
# Creates:
# my-service/
# ├── handler.py (Lambda function code)
# ├── serverless.yml (configuration file)
# └── .gitignore
Deploy the full stack
# Deploy all functions and infrastructure (verbose output)
sls deploy -v
This packages your code, creates a CloudFormation stack, deploys all Lambda functions, and outputs the API endpoints.
Deploy a single function (faster for code changes)
# Deploy only the updated function (skips CloudFormation)
sls deploy function -f functionName
Invoke a function
# Invoke and show logs
sls invoke -f functionName -l
# Invoke with a JSON payload
sls invoke -f functionName -d '{"key": "value"}' -l
View logs
# Tail live CloudWatch logs for a function
sls logs -f functionName -t
Remove the deployment
# Delete all deployed resources (CloudFormation stack)
sls remove
Local development
# Run a function locally without deploying
sls invoke local -f functionName -d '{"key": "value"}'
Basic serverless.yml structure
service: my-service
provider:
name: aws
runtime: python3.12
region: us-east-1
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get