Serverless Framework Docs

#Knative - Introduction

The Serverless Framework helps you develop and deploy your Knative Serving services, along with the Knative Eventing configurations as event sources. It's a CLI that offers structure, automation and best practices out-of-the-box, allowing you to focus on building sophisticated, event-driven, serverless architectures, comprised of functions and fvents.

The Serverless Framework is different from other application frameworks because:

  • It manages your code as well as your infrastructure
  • It supports multiple languages (Node.js, Python, PHP, and more)

#Core Concepts

Here are the Framework's main concepts and how they pertain to Knative primitives.

#Functions

A Function is a Knative Serving service. It's an independent unit of deployment, like a microservice. It's merely code, deployed in the cloud, that is most often written to perform a single job such as:

  • Saving a user to the database
  • Processing a file in a database
  • Performing a scheduled task

You can perform multiple jobs in your code, but we don't recommend doing that without good reason. Separation of concerns is best and the Framework is designed to help you easily develop and deploy functions, as well as manage lots of them.

#Events

Anything that triggers a Knative Serving service to execute is regarded by the Framework as an Event. Events are Knative Eventing sources such as:

  • A Kafka event
  • AWS SQS queue element
  • A scheduled task (e.g., run every 5 minutes)
  • And more...

When you define an event for your functions in the Serverless Framework, the Framework will automatically create any infrastructure necessary for that event (e.g., a Knative Trigger) and configure your Knative Serving functions to listen to it.

#Resources

Resources are Knative infrastructure components which your Functions use such as:

  • A Kafka event source
  • AWS SQS event source
  • A scheduled task (e.g., run every 5 minutes)
  • And more...

#Services

A Service is the Framework's unit of organization. You can think of it as a project file, though you can have multiple services for a single application. It's where you define your Functions, the Events that trigger them, and the Resources your Functions use, all in one file entitled serverless.yml (or serverless.json or serverless.js). It looks like this:

service: users

functions: # Your "Functions"
  functionOne:
    events: # The "Events" that trigger this function
      - kafka:
          consumerGroup: KAFKA_CONSUMER_GROUP_NAME
          bootstrapServers:
            - server1
            - server2
          topics:
            - my-topic
  functionTwo:
    events:
      - cron:
          schedule: '* * * * *'
          data: '{"message": "Hello world from a Cron event source!"}'

When you deploy with the Framework by running serverless deploy, everything in serverless.yml is deployed at once.

#Plugins

You can overwrite or extend the functionality of the Framework using Plugins. Every serverless.yml can contain a plugins: property, which features multiple plugins.

plugins:
  - serverless-knative
  - serverless-secrets

Have questions?

Head over to the forums to search for your questions and issues or post a new one.