Serverless Framework

4.34.0 · active · verified Tue Apr 21

The Serverless Framework is a powerful command-line interface (CLI) tool designed for deploying serverless applications, primarily leveraging AWS services like Lambda, API Gateway, and DynamoDB. It enables developers to define both their application code and the necessary cloud infrastructure using declarative YAML configurations. Currently in its v4 series (e.g., v4.34.0 as of the latest release info), it undergoes active development with frequent minor and patch releases. The framework supports multiple programming runtimes including Node.js, Python, Go, and Java. Key differentiators include its extensive extensibility via a plugin ecosystem, the recent integration of popular community plugins (e.g., AppSync, Prune) into its core, and built-in support for advanced features like Durable Functions and S3 Filesystem mounts for Lambda. It aims to optimize for cost-effectiveness, auto-scaling, and reduced maintenance by abstracting complex cloud provisioning, facilitating the entire application lifecycle from development to deployment.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart defines a basic AWS Lambda function with an API Gateway endpoint using `serverless.yml`. It shows a minimal configuration for a Node.js function, demonstrates environment variable usage, and includes typical CLI commands for deployment and local development.

service: my-serverless-app

frameworkVersion: '4'

provider:
  name: aws
  runtime: nodejs20.x
  region: us-east-1
  environment:
    MY_API_KEY: ${env:MY_API_KEY, 'default_key'}

functions:
  hello:
    handler: handler.hello
    events:
      - httpApi:
          path: /hello
          method: get

plugins:
  - serverless-offline # Example plugin

# handler.js
// module.exports.hello = async (event) => {
//   return {
//     statusCode: 200,
//     body: JSON.stringify(
//       {
//         message: `Hello from Serverless! API Key: ${process.env.MY_API_KEY}`,
//         input: event,
//       },
//       null,
//       2
//     ),
//   };
// };

# To deploy: 
# npm install -g serverless
# sls deploy
# To run locally with serverless-offline (if installed):
# sls offline

view raw JSON →