The Serverless Framework – Makes it easy to use AWS Lambda and other managed cloud services to build applications that auto-scale, cost nothing when idle, and boast radically low maintenance.
The Serverless Framework is a command-line tool with approachable YAML syntax to deploy both your code and cloud infrastructure needed to make tons of serverless application use-cases, like APIs, front-ends, data pipelines and scheduled tasks. It's a multi-language framework that supports Node.js, Typescript, Python, Go, Java, and more. It's also completely extensible via over 1,000 plugins which add more serverless use-cases and workflows to the Framework.
Actively maintained by Serverless Inc.
Serverless Framework - V.4 - Alpha
This is the Serverless Framework V.4 Alpha release. It includes the following:
- No breaking changes for the "aws" Provider.
- A transition to a binary core, making Node.js not a requirement.
- Support for automatic updates.
- Improved onboarding and set-up assistance.
- Built-in CLI support command.
- Improved support for AWS SSO credentials.
- Authorization with the Serverless Platform.
- Deprecation of other cloud provider, in favor of upcoming "Extensions".
Contents
Features
- Build More, Manage Less: Innovate faster by spending less time on infrastructure management.
- Maximum Versatility: Tackle diverse serverless use cases, from APIs and scheduled tasks to web sockets and data pipelines.
- Automated Deployment: Streamline development with code and infrastructure deployment handled together.
- Ease of Use: Deploy complex applications without deep cloud infrastructure expertise, thanks to simple YAML configuration.
- Language Agnostic: Build in your preferred language – Node.js, Python, Java, Go, C#, Ruby, Swift, Kotlin, PHP, Scala, or F#.
- Complete Lifecycle Management: Build, deploy, monitor, update, and troubleshoot serverless applications with ease.
- Scalable Organization: Structure large projects and teams efficiently with multi-domain support.
- Effortless Environments: Seamlessly manage development, staging, and production environments.
- Customization Ready: Extend and modify the Framework's functionality with a rich plugin ecosystem.
- Vibrant Community: Get support and connect with a passionate community of Serverless developers.
Quick Start
The Serverless Framework is packaged as a binary, which can be installed via this CURL script.
curl -o- -L https://install.serverless.com | bash
You can also install the Framework via NPM. You will need to have Node.js installed.
npm i @serverlessinc/framework -g
Create A Project
Run the interactive onboarding via the "serverless" command, to pick a Template and set-up credentials for AWS.
serverless
During onboarding, you can set up AWS credentials a few ways. You can simply add them as environment variables, which is best if you're using AWS SSO. You can have the Serverless Framework Platform store an AWS IAM Role for you and your team to share and assign to specific Stages, or you can persist long-term credentials to an AWS Profile on your local machine. We recommend the first two options.
After onboarding, move into the newly created directory.
cd [your-new-project-name]
Your new project will contain a serverless.yml file with simple syntax for deploying infrastructure to AWS, such as AWS Lambda functions, infrastructure that triggers those functions with events, and additional infrastructure your AWS Lambda functions may need for various use-cases. Learn more about this in the Core Concepts documentation.
Deploy to AWS
Run the deploy command to deploy your project to AWS. Note, you can use serverless or sls as the command prompt.
sls deploy
The deployed AWS Lambda functions and other essential information such as API Endpoint URLs will be displayed in the command output.
More details on deploying can be found here.
Develop On The Cloud
Many Serverless Framework users choose to develop on the cloud, since it matches reality and emulating Lambda locally can be complex. To develop on the cloud quickly, without sacrificing speed, we recommend the following workflow...
To deploy code changes quickly, skip the serverless deploy command which is much slower since it triggers a full AWS CloudFormation update. Instead, deploy code and configuration changes to individual AWS Lambda functions in seconds via the deploy function command, with -f [function name in serverless.yml] set to the function you want to deploy.
sls deploy function -f my-api
More details on the deploy function command can be found here.
To invoke your AWS Lambda function on the cloud, you can find URLs for your functions w/ API endpoints in the serverless deploy output, or retrieve them via serverless info. If your functions do not have API endpoints, you can use the invoke command, like this:
sls invoke -f hello
# Invoke and display logs:
serverless invoke -f hello --log
More details on the invoke command can be found here.
To stream your logs while you work, use the sls logs command in a separate terminal window:
sls logs -f [Function name in serverless.yml] -t
Target a specific function via the -f option and enable streaming via the -t option.
Develop Locally
Many Serverless Framework users rely on local emulation to develop more quickly. Please note, emulating AWS Lambda and other cloud services is never accurate and the process can be complex. We recommend the following workflow to develop locally...
Use the invoke local command to invoke your function locally:
sls invoke local -f my-api
You can also pass data to this local invocation via a variety of ways. Here's one of them:
sls invoke local --function functionName --data '{"a":"bar"}'
More details on the invoke local command can be found here
Serverless Framework also has a great plugin that allows you to run a server locally and emulate AWS API Gateway. This is the serverless-offline command.
More details on the serverless-offline plugins command can be found here
Use Plugins
A big benefit of Serverless Framework is within its Plugin ecosystem.
Plugins extend or overwrite the Serverless Framework, giving it new use-cases or capabilites, and there are hundreds of them.
Some of the most common Plugins are:
- Serverless Offline - Emulate AWS Lambda and API Gateway locally when developing your Serverless project.
- Serverless ESBuild - Bundles JavaScript and TypeScript extremely fast via esbuild.
- Serverless Domain Manager - Manage custom domains with AWS API Gateways.
- Serverless Step Functions - Build AWS Step Functions architectures.
- Serverless Python Requirements - Bundle dependencies from requirements.txt and make them available in your PYTHONPATH.
Remove Your Service
If you want to delete your service, run 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.
sls remove
More details on the remove command can be found here.
What's Next
Here are some helpful resources for continuing with the Serverless Framework:
- Study Serverless Framework's core concepts
- Get inspiration from these Serverless Framework templates
- Discover all of the events that can trigger Lambda functions
- Bookmark Serverless Framework's
serverless.ymlguide - Search the plugins registry to extend Serverless Framework