A Look at the Serverless Framework

The Serverless framework gave Serverless its name, so I wanted to take a closer look at what it provides, and how it contributed to where we are today.

The framework is downloadable from serverless.com and provides a command line interface (CLI) for creating and manipulating serverless functions.

It works with:

  • Amazon AWS
  • Microsoft Azure
  • IBM OpenWhisk
  • Google Cloud Platform
  • Kubeless
  • SpotInst
  • Auth0 Webtasks

It ships as an NPM package and relies on NodeJS v6.5.o or greater.  The basic framework is installed via  npm install -g serverless and then you add the vendor-specific extension packages (such as  npm install -g serverless-azure-functions for Azure). At the time of writing the latest version is 1.26.1, and like a lot of NPM packages, it pulls in quite a screenful of dependencies.

The interface runs under Node so should work where-ever Node runs, so you’re covered on Windows, Mac, and Linux.

Creating

Functions can be created by the CLI using templates.  If you look at the help you get a complete list of available out-of-the-box templates:

Available templates: "aws-nodejs", "aws-nodejs-typescript", "aws-nodejs-ecma-script", "aws-python", "aws-python3", "aws-groovy-gradle", "aws-java-maven", "aws-java-gradle", "aws-kotlin-jvm-maven", "aws-kotlin-jvm-gradle", "aws-kotlin-nodejs-gradle", "aws-scala-sbt", "aws-csharp", "aws-fsharp", "aws-go", "aws-go-dep", "azure-nodejs", "google-nodejs", "kubeless-python", "kubeless-nodejs", "openwhisk-nodejs", "openwhisk-php", "openwhisk-python", "openwhisk-swift", "spotinst-nodejs", "spotinst-python", "spotinst-ruby", "spotinst-java8", "webtasks-nodejs", "plugin" and "hello-world"

So most options are covered out of the box, including Javascript, Python, Java and .NET. I’m not going to cover everything here so you can follow along with the tutorials on their site.

You can also pull existing services straight from Github and modify those instead of creating them from scratch.

Authenticating

When running serverless deployfor the first time, you will be prompted to log in interactively, then your details are stored in a credential for subsequent use.

Plugins

The framework comes with a large plugin repository to integrate with a variety of different services and call out to various utilities as part of the deployment process.

$ serverless plugin list
raml-serverless - Serverless plugin to work with RAML API spec documents
serverless-alexa-plugin - Serverless plugin to support Alexa Lambda events
serverless-alexa-skills - Manage your Alexa Skills with Serverless Framework.
serverless-api-cloudfront - Plugin that adds CloudFront distribution in front of your API Gateway for custom domain, CDN caching and access log.
serverless-api-stage - Serverless API Stage plugin, enables stage variables and logging for AWS API Gateway.
serverless-apig-s3 - Serve static front-end content from S3 via the API Gateway and deploy client bundle to S3.
serverless-apigateway-plugin - Configure the AWS api gateway: Binary support, Headers and Body template mappings
serverless-apigw-binary - Plugin to enable binary support in AWS API Gateway.
serverless-apigwy-binary - Serverless plugin for configuring API Gateway to return binary responses
serverless-appsync-plugin - Serverless Plugin to deploy AppSync GraphQL API
serverless-attach-managed-policy - A Serverless plugin to automatically attach an AWS Managed IAM Policy (or Policies) to all IAM Roles created by the Service.
serverless-aws-alias - This plugin enables use of AWS aliases on Lambda functions.
serverless-aws-documentation - Serverless plugin to add documentation and models to the serverless generated API Gateway
serverless-aws-nested-stacks - Yet another AWS nested stack plugin!
serverless-aws-resource-names - Serverless plugin to alter the default naming conventions for sls resources via a simple mapping file.
serverless-build-plugin - A Node.js focused build plugin for serverless.
serverless-cf-vars - Enables use of AWS pseudo functions and Fn::Sub string substitution
serverless-cljs-plugin - Enables Clojurescript as an implementation language for Lambda handlers
serverless-cloudformation-changesets - Natively deploy to CloudFormation via Change sets, instead of directly. Allowing you to queue changes, and safely require escalated roles for final deployment.
serverless-cloudformation-parameter-setter - Set CloudFormation parameters when deploying.
serverless-cloudformation-resource-counter - A plugin to count the resources generated in the AWS CloudFormation stack after deployment.
serverless-cloudformation-sub-variables - Serverless framework plugin for easily supporting AWS CloudFormation Sub function variables
serverless-coffeescript - A Serverless plugin to compile your CoffeeScript into JavaScript at deployment
serverless-command-line-event-args - This module is Serverless Framework plugin. Event JSON passes to your Lambda function in commandline.
serverless-content-encoding - Enable Content Encoding in AWS API Gateway during deployment
serverless-crypt - Securing the secrets on Serverless Framework by AWS KMS encryption.
serverless-custom-packaging-plugin - Plugin to package your sourcecode using a custom target path inside the zip.
serverless-dir-config-plugin - EXPERIMENTAL - Serverless plugin to load function and resource definitions from a directory.
serverless-domain-manager - Serverless plugin for managing custom domains with API Gateways.
serverless-dotenv - Fetch environment variables and write it to a .env file
serverless-dotnet - A serverless plugin to run 'dotnet' commands as part of the deploy process
serverless-dynalite - Run dynalite locally (no JVM, all JS) to simulate DynamoDB. Watch serverless.yml for table config updates.
serverless-dynamodb-autoscaling - Configure Amazon DynamoDB's native Auto Scaling for your table capacities.
serverless-dynamodb-local - Serverless Dynamodb Local Plugin - Allows to run dynamodb locally for serverless
serverless-dynamodb-ttl - Configure DynamoDB TTL in serverless.yml (until CloudFormation supports this).
serverless-enable-api-logs - Enables Coudwatch logging for API Gateway events
serverless-env-generator - Manage environment variables with YAML and load them with dotenv. Supports variable encryption with KMS, multiple stages and custom profiles.
serverless-ephemeral - Build and include custom stateless libraries for any language
serverless-event-constant-inputs - Allows you to add constant inputs to events in Serverless 1.0. For more info see [constant values in Cloudwatch](https://aws.amazon.com/blogs/compute/simply-serverless-use-constant-values-in-cloudwatch-event-triggered-lambda-functions/)
serverless-export-env - Export environment variables into a .env file with automatic AWS CloudFormation reference resolution.
serverless-functions-base-path - Easily define a base path where your serverless functions are located.
serverless-go-build - Build go source files (or public functions) using yml definition file
serverless-gulp - A thin task wrapper around @goserverless that allows you to automate build, test and deploy tasks using gulp
serverless-haskell - Deploying Haskell applications to AWS Lambda with Serverless
serverless-hooks-plugin - Run arbitrary commands on any lifecycle event in serverless
serverless-iam-roles-per-function - Serverless Plugin for easily defining IAM roles per function via the use of iamRoleStatements at the function level.
serverless-iot-local - AWS Iot events with serverless-offline
serverless-jest-plugin - A Serverless Plugin for the Serverless Framework which adds support for test-driven development using Jest
serverless-kms-secrets - Allows to easily encrypt and decrypt secrets using KMS from the serverless CLI
serverless-kubeless - Serverless plugin for deploying functions to Kubeless.
serverless-local-dev-server - Speeds up development of Alexa Skills, Chatbots and APIs by exposing your functions as local HTTP endpoints and mapping received events.
serverless-local-environment - Serverless plugin to set local environment variables and remote environment variable to different values
serverless-log-forwarding - Serverless plugin for forwarding CloudWatch logs to another Lambda function.
serverless-micro - Plugin to help manage multiple micro services under one main service.
serverless-mocha-plugin - A Serverless Plugin for the Serverless Framework which adds support for test-driven development using Mocha
serverless-nested-stack - A plugin to Workaround for Cloudformation 200 resource limit
serverless-offline - Emulate AWS λ and API Gateway locally when developing your Serverless project
serverless-offline-scheduler - Runs scheduled functions offline while integrating with serverless-offline
serverless-offline-sns - Serverless plugin to run a local SNS server and call serverless SNS handlers with events notifications.
serverless-offline-ssm - Read SSM parameters from a .env file instead of AWS
serverless-package-python-functions - Packaging Python Lambda functions with only the dependencies/requirements they need.
serverless-parameters - Add parameters to the generated cloudformation templates
serverless-plugin-api-docs - Serverless plugin to automatically create a lambda function which returns Swagger-UI HTML API Documentation Page based on the given swagger spec JSON file.
serverless-plugin-aws-alerts - A Serverless plugin to easily add CloudWatch alarms to functions
serverless-plugin-aws-resolvers - Resolves variables from ESS, RDS, or Kinesis for serverless services
serverless-plugin-bespoken - Creates a local server and a proxy so you don't have to deploy anytime you want to test your code
serverless-plugin-bind-deployment-id - A Serverless plugin to bind the randomly generated deployment resource to your custom resources
serverless-plugin-browserifier - Reduce the size and speed up your Node.js based lambda's using browserify.
serverless-plugin-browserify - Speed up your node based lambda's
serverless-plugin-canary-deployments - A Serverless plugin to implement canary deployments of Lambda functions
serverless-plugin-cfauthorizer - This plugin allows you to define your own API Gateway Authorizers as the Serverless CloudFormation resources and apply them to HTTP endpoints.
serverless-plugin-chrome - Plugin which bundles and ensures that Headless Chrome/Chromium is running when your AWS Lambda function handler is invoked.
serverless-plugin-cloudwatch-sumologic - Plugin which auto-subscribes a log delivery lambda function to lambda log groups created by serverless
serverless-plugin-common-excludes - Adds commonly excluded files to package.excludes
serverless-plugin-custom-domain - Reliably sets a BasePathMapping to an API Gateway Custom Domain
serverless-plugin-deploy-environment - Plugin to manage deployment environment across stages
serverless-plugin-diff - Compares your local AWS CloudFormation templates against deployed ones.
serverless-plugin-dynamodb-autoscaling - Auto generate auto scaling configuration for configured DynamoDB tables
serverless-plugin-elastic-beanstalk - A serverless plugin to deploy applications to AWS ElasticBeanstalk.
serverless-plugin-encode-env-var-objects - Serverless plugin to encode any environment variable objects.
serverless-plugin-external-sns-events - Add ability for functions to use existing or external SNS topics as an event source
serverless-plugin-git-variables - A Serverless plugin to expose git variables (branch name, HEAD description, full commit hash) to your serverless services
serverless-plugin-graphiql - A Serverless plugin to run a local http server for graphiql and your graphql handler
serverless-plugin-include-dependencies - This is a Serverless plugin that should make your deployed functions smaller.
serverless-plugin-inject-dependencies - Painlessly deploy serverless projects with only the required dependencies.
serverless-plugin-iopipe - See inside your Lambda functions with high fidelity metrics and monitoring.
serverless-plugin-lambda-dead-letter - A Serverless plugin that can configure a lambda with a dead letter queue or topic
serverless-plugin-log-subscription - Adds a CloudWatch LogSubscription for functions
serverless-plugin-metric - Creates dynamically AWS metric-filter resources with custom patterns
serverless-plugin-multiple-responses - Enable multiple content-types for Response template
serverless-plugin-node-shim - Serverless plugin to run your functions in nodejs version (8 LTS, 9+) on aws lambda
serverless-plugin-offline-kinesis-events - Plugin that works with serverless-offline to allow offline testing of serverless functions that are triggered by Kinesis events.
serverless-plugin-optimize - Bundle with Browserify, transpile with Babel to ES5 and minify with Uglify your Serverless functions.
serverless-plugin-package-dotenv-file - A Serverless plugin to copy a .env file into the serverless package
serverless-plugin-provider-groups - A plugin to allow management of grouped settings within large serverless projects.
serverless-plugin-reducer - Reduce Node.js lambda package so it contains only lambda dependencies
serverless-plugin-scripts - Add scripting capabilities to the Serverless Framework
serverless-plugin-select - Select which functions are to be deployed based on region and stage.
serverless-plugin-simulate - Simulate AWS Lambda and API Gateway locally using Docker
serverless-plugin-split-stacks - Migrate certain resources to nested stacks
serverless-plugin-stack-config - A serverless plugin to manage configurations for a stack across micro-services.
serverless-plugin-stack-outputs - Displays stack outputs for your serverless stacks when `sls info` is ran
serverless-plugin-stackstorm - Reusable Functions from StackStorm Exchange
serverless-plugin-stage-variables - Add stage variables for Serverless 1.x to ApiGateway, so you can use variables in your Lambda's
serverless-plugin-subscription-filter - A serverless plugin to register AWS CloudWatchLogs subscription filter
serverless-plugin-tracer - Trace serverless hooks as they execute
serverless-plugin-transpiler - Transpile lambda files during packaging step
serverless-plugin-typescript - Serverless plugin for zero-config Typescript support.
serverless-plugin-vpc-eni-cleanup - Automatic cleanup of VPC network interfaces on stage removal
serverless-plugin-warmup - Keep your lambdas warm during Winter.
serverless-plugin-webpack - A serverless plugin to automatically bundle your functions individually with webpack
serverless-plugin-write-env-vars - Write environment variables out to a file that is compatible with dotenv
serverless-prune-plugin - Deletes old versions of functions from AWS, preserving recent and aliased versions
serverless-pseudo-parameters - Use ${AWS::AccountId} and other cloudformation pseudo parameters in your serverless.yml values
serverless-python-individually - A serverless framework plugin to install multiple lambda functions written in python
serverless-python-requirements - Serverless plugin to bundle Python packages
serverless-reqvalidator-plugin - Serverless plugin to add request validator to API Gateway methods
serverless-resources-env - After Deploy, this plugin fetches cloudformation resource identifiers and sets them on AWS lambdas, and creates local .<state>-env file
serverless-run-function-plugin - Run serverless function locally
serverless-s3-encryption - Set or remove the encryption settings on your s3 buckets
serverless-s3-remover - A serverless plugin to make s3 buckets empty before deleting cloudformation stack when ```sls remove```
serverless-s3-sync - A plugin to sync local directories and S3 prefixes for Serverless Framework,
serverless-s3bucket-sync - Sync a local folder with a S3 bucket after sls deploy
serverless-sam - Exports an AWS SAM template for a service created with the Serverless Framework.
serverless-scriptable-plugin - Customize Serverless behavior without writing a plugin.
serverless-sentry - Automatic monitoring of memory usage, execution timeouts and forwarding of Lambda errors to Sentry (https://sentry.io).
serverless-shell - Drop to a runtime shell with all the environment variables set that you'd have in lambda.
serverless-sns-filter - Serverless plugin to add SNS Subscription Filters to events
serverless-spa - Serverless plugin to deploy your website to AWS S3 using Webpack to bundle it.
serverless-sqs-alarms-plugin - Wrapper to setup CloudWatch Alarms on SQS queue length
serverless-sqs-fifo - A serverless plugin to handle creation of sqs fifo queue's in aws (stop-gap)
serverless-ssm-fetch - Sets "AWS Systems Manager Parameter Store (SSM)" parameters into functions' environment variables.
serverless-stack-output - Store output from your AWS CloudFormation Stack in JSON/YAML/TOML files, or to pass it to a JavaScript function for further processing.
serverless-stage-manager - Super simple Serverless plugin for validating stage names before deployment
serverless-static - Easily serve files from a folder while developing on localhost with the serverless-offline plugin
serverless-step-functions - AWS Step Functions with Serverless Framework.
serverless-sthree-env - Serverless plugin to get config from a json formatted file in S3 and copy them to environment variable
serverless-subscription-filter - Serverless plugin to register subscription filter for Lambda logs. Register and pipe the logs of one lambda to another to process.
serverless-vpc-discovery - Serverless plugin for discovering VPC / Subnet / Security Group configuration by name.
serverless-webpack - Serverless plugin to bundle your lambdas with Webpack
serverless-wsgi - Serverless plugin to deploy WSGI applications (Flask/Django/Pyramid etc.) and bundle Python package

Deploying

You can either deploy your entire service with a straightforward  serverless deploy command, or deploy individual functions which is useful for small incremental changes.  Because your configuration is also stored as code, you get repeatable deployments as well as cross-compatibility.

Impressions

The serverless framework provides a useful layer above the cloud vendor’s implementation, abstracting away differences and making your code more portable. Although the decision to change between cloud vendors isn’t taken lightly or often, it’s good to know that it can be done without major upheaval. This does of course depend on the other services you may be utilising, such as blob storage, databases, and queueing systems. The serverless space is still young, but projects such as this help move the state-of-the-art forward. We’ll never get Microsoft and Amazon to agree on a common interface so we’re always going to need abstractions like this.

Leave a Reply

Your email address will not be published. Required fields are marked *