• Stars
    star
    266
  • Rank 154,103 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework

Azure Functions Serverless Plugin - Currently looking for active maintainers

Reach out to contactATserverless.com to discuss becoming a maintainer if interested.

This plugin enables Azure Functions support within the Serverless Framework.

Build Status Code Coverage npm version

Quickstart

Pre-requisites

  1. Node.js 8.x or above
  2. Serverless CLI v1.9.0+. You can run npm i -g serverless if you don't already have it.
  3. An Azure account. If you don't already have one, you can sign up for a free trial that includes $200 of free credit.

Create a new Azure Function App

# Create Azure Function App from template
# Templates include: azure-nodejs, azure-python, azure-dotnet
$ sls create -t azure-nodejs -p <appName>
# Move into project directory
$ cd <appName>
# Install dependencies (including this plugin)
$ npm install

The serverless.yml file contains the configuration for your service. For more details on its configuration, see the docs.

Running Function App Locally (offline plugin)

At the root of your project directory, run:

# Builds necessary function bindings files and starts the function app
$ sls offline

The offline process will generate a directory for each of your functions, which will contain a file titled function.json. This will contain a relative reference to your handler file & exported function from that file as long as they are referenced correctly in serverless.yml.

After the necessary files are generated, it will start the function app from within the same shell. For HTTP functions, the local URLs will be displayed in the console when the function app is initialized.

To build the files without spawning the process to start the function app, run:

$ sls offline build

To simply start the function app without building the files, run:

$ sls offline start

To clean up files generated from the build, run:

$ sls offline cleanup

To pass additional arguments to the spawned func host start process, add them as the option spawnargs (shortcut a). Example:

$ sls offline -a "--cors *"

This works for sls offline or sls offline start

Dry-Run Deployment

Before you deploy your new function app, you may want to double check the resources that will be created, their generated names and other basic configuration info. You can run:

# -d is short for --dryrun
$ sls deploy --dryrun

This will print out a basic summary of what your deployed service will look like.

For a more detailed look into the generated ARM template for your resource group, add the --arm (or -a) flag:

$ sls deploy --dryrun --arm

Deploy Your Function App

Deploy your new service to Azure! The first time you do this, you will be asked to authenticate with your Azure account, so the serverless CLI can manage Functions on your behalf. Simply follow the provided instructions, and the deployment will continue as soon as the authentication process is completed.

$ sls deploy

For more advanced deployment scenarios, see our deployment docs

Get a Summary of Your Deployed Function App

To see a basic summary of your application (same format as the dry-run summary above), run:

$ sls info

To look at the ARM template for the last successful deployment, add the --arm (or -a) flag:

$ sls info --arm

You can also get information services with different stages, regions or resource groups by passing any of those flags. Example:

$ sls info --stage prod --region westus2

Test Your Function App

Invoke your HTTP functions without ever leaving the CLI using:

$ sls invoke -f <functionName>
Invoke Options
  • -f or --function - Function to Invoke
  • -d or --data - Stringified JSON data to use as either query params or request body
  • -p or --path - Path to JSON file to use as either query params or request body
  • -m or --method - HTTP method for request
Example

After deploying template function app, run

$ sls invoke -f hello -d '{"name": "Azure"}'

If you have a JSON object in a file, you could run

$ sls invoke -f hello -p data.json

If you have your service running locally (in another terminal), you can run:

$ sls invoke local -f hello -p data.json

If you configured your function app to run with APIM, you can run:

$ sls invoke apim -f hello -p data.json

Roll Back Your Function App

To roll back your function app to a previous deployment, simply select a timestamp of a previous deployment and use rollback command.

# List all deployments to know the timestamp for rollback
$ sls deploy list
Serverless:
-----------
Name: myFunctionApp-t1561479533
Timestamp: 1561479533
Datetime: 2019-06-25T16:18:53+00:00
-----------
Name: myFunctionApp-t1561479506
Timestamp: 1561479506
Datetime: 2019-06-25T16:18:26+00:00
-----------
Name: myFunctionApp-t1561479444
Timestamp: 1561479444
Datetime: 2019-06-25T16:17:24+00:00
-----------

# Rollback Function App to timestamp
$ sls rollback -t 1561479506

This will update the app code and infrastructure to the selected previous deployment.

For more details, check out our rollback docs.

Deleting Your Function App

If at any point you no longer need your service, you can run the following command to delete the resource group containing your Azure Function App and other depoloyed resources using:

$ sls remove

You will then be prompted to enter the full name of the resource group as an extra safety before deleting the entire resource group.

You can bypass this check by running:

$ sls remove --force

Creating or removing Azure Functions

To create a new Azure Function within your function app, run the following command from within your app's directory:

# -n or --name for name of new function
$ sls func add -n {functionName}

This will create a new handler file at the root of your project with the title {functionName}.js. It will also update serverless.yml to contain the new function.

To remove an existing Azure Function from your function app, run the following command from within your app's directory:

# -n or --name for name of function to remove
$ sls func remove -n {functionName}

This will remove the {functionName}.js handler and remove the function from serverless.yml

*Note: Add & remove currently only support HTTP triggered functions. For other triggers, you will need to update serverless.yml manually

Advanced Authentication

The getting started walkthrough illustrates the interactive login experience, which is recommended when getting started. However, for more robust use, a service principal is recommended for authentication.

Creating a Service Principal
  1. Install the Azure CLI

  2. Login via Azure CLI and set subscription

    # Login to Azure
    $ az login
    # Set Azure Subscription for which to create Service Principal
    $ az account set -s <subscription-id>
  3. Generate Service Principal for Azure Subscription

    # Create SP with unique name
    $ az ad sp create-for-rbac --name <my-unique-name>

    This will yield something like:

    {
      "appId": "<servicePrincipalId>",
      "displayName": "<name>",
      "name": "<name>",
      "password": "<password>",
      "tenant": "<tenantId>"
    }
  4. Set environment variables with values from above service principal

    Bash

    $ export AZURE_SUBSCRIPTION_ID='<subscriptionId (see above, step 2)>'
    $ export AZURE_TENANT_ID='<tenantId>'
    $ export AZURE_CLIENT_ID='<servicePrincipalId>'
    $ export AZURE_CLIENT_SECRET='<password>'

    Powershell

    $env:AZURE_SUBSCRIPTION_ID='<subscriptionId (see above, step 2)>'
    $env:AZURE_TENANT_ID='<tenantId>'
    $env:AZURE_CLIENT_ID='<servicePrincipalId>'
    $env:AZURE_CLIENT_SECRET='<password>'

Example Usage

Logging Verbosity

You can set the logging verbosity with the --verbose flag. If the --verbose flag is set with no value, logging will be as verbose as possible (debug mode). You can also provide a value with the flag to set the verbosity to a specific level:

  • --verbose error - Only error messages printed
  • --verbose warn - Only error and warning messages printed
  • --verbose info - Only error, warning and info messages printed
  • --verbose debug - All messages printed

Contributing

Please create issues in this repo for any problems or questions you find. Before sending a PR for any major changes, please create an issue to discuss.

We're still in the process of getting everying running 100%, but please refer to the Serverless contributing guidlines for information on how to contribute and code of conduct.

Local dev

  1. Clone this repository to your local machine
  2. Navigate to the cloned folder
  3. Run npm install
  4. Run npm run build
  5. Navigate to a folder where you created a new Serverless project, run npm install, and then run npm link {path to serverless-azure-functions folder}. Running npm install after the link command may override the link.
  6. The npm modules should now contain your local version of this plugin.

Unit Tests

We use Jest for unit tests, and it is expected that every Pull Request containing code changes have accompanying unit tests.

Run unit tests using npm test or npm run test:coverage to get coverage results.

Integration Tests

We run our integration tests twice per day from our GitHub workflow. These tests install the beta version of the plugin, deploy a function app (with APIM), re-deploy (to make sure ARM template deployment is skipped), invoke the function directly, invoke the APIM endpoint and then remove the resource group, making assertions on the output at each step. While the number of configurations one could use in the Serverless Framework is virtually infinite, we tried to capture the main runtimes and platforms that are supported by the tool:

  • Node 10 on Linux using remote build
  • Node 10 on Linux using external package
  • Node 10 on Windows
  • Node 10 on Windows using webpack
  • Node 12 on Linux using remote build
  • Node 12 on Linux using external package
  • Node 12 on Linux using remote build and premium functions
  • Node 12 on Windows
  • Node 12 on Windows using premium functions
  • Node 12 on Windows using webpack
  • Node 14 on Windows
  • Node 14 on Windows using premium functions
  • Node 14 on Windows using webpack
  • Python 3.6 (Linux only)
  • Python 3.6 (Linux only) using premium functions
  • Python 3.7 (Linux only)
  • Python 3.8 (Linux only)
  • .NET Core 2.2 on Linux
  • .NET Core 2.2 on Windows
  • .NET Core 3.1 on Linux
  • .NET Core 3.1 on Windows

We made these configurations as minimal as possible. If you are having problems with your project, feel free to check to see if our integration tests are passing (see badge at top of readme) and then double check our configuration inside the integrationTests directory.

We use Clover to run the integration tests, and they run 2x per day in our GitHub Action, split out by runtime language.

Signing commits

All commits in your Pull Request will need to be signed. When looking at the commits in the pull request, you will see a green 'verified' icon next to your commit. Commit signature verification is discussed here.

Follow the directions here to configure commit signing.

If any of your commits are not signed, your pull request will not be able to be merged into the base branch. You can fix this by squashing any unsigned commits into signed commits using an interactive rebase, and force pushing your new commit history. More detail here.

When using Windows you may also encounter an error when trying to sign a commit, stating that a security key could not be found. Ensure that you have set the path the gpg in the git config: git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

License

MIT

More Repositories

1

serverless

⚡ Serverless Framework – Use AWS Lambda and other managed cloud services to build apps that auto-scale, cost nothing when idle, and boast radically low maintenance.
JavaScript
46,101
star
2

examples

Serverless Examples – A collection of boilerplates and examples of serverless architectures built with the Serverless Framework on AWS Lambda, Microsoft Azure, Google Cloud Functions, and more.
JavaScript
11,353
star
3

serverless-graphql

Serverless GraphQL Examples for AWS AppSync and Apollo
JavaScript
2,720
star
4

components

The Serverless Framework's new infrastructure provisioning technology — Build, compose, & deploy serverless apps in seconds...
JavaScript
2,306
star
5

event-gateway

React to any event with serverless functions across clouds
Go
1,647
star
6

serverless-python-requirements

⚡️🐍📦 Serverless plugin to bundle Python packages
JavaScript
1,108
star
7

plugins

Serverless Plugins – Extend the Serverless Framework with these community driven plugins –
JavaScript
970
star
8

aws-ai-stack

AWS AI Stack – A ready-to-use, full-stack boilerplate project for building serverless AI applications on AWS
JavaScript
911
star
9

serverless-graphql-blog

A Serverless Blog leveraging GraphQL to offer a REST API with only 1 endpoint using Serverless v0.5
JavaScript
793
star
10

serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
TypeScript
776
star
11

github-action

⚡:octocat: A Github Action for deploying with the Serverless Framework
Dockerfile
642
star
12

scope

🔭 Scope - Create a birdeye's view of your Github project and embed on your site
JavaScript
456
star
13

guide

Serverless Guide - An open-source definitive guide to serverless architectures.
Shell
439
star
14

serverless-kubeless

This plugin enables support for Kubeless within the Serverless Framework.
JavaScript
302
star
15

serverless-google-cloudfunctions

Serverless Google Cloud Functions Plugin – Adds Google Cloud Functions support to the Serverless Framework
JavaScript
272
star
16

post-scheduler

Schedule posts & content updates for static websites (Jekyll, Hugo, Gatsby, Phenomic etc)
JavaScript
191
star
17

serverless-starter

A boilerplate for new Serverless Projects
JavaScript
190
star
18

blog

serverless.com/blog – Posts from the Serverless community & core team. Contributions welcome!
JavaScript
183
star
19

serverless-client-s3

A plugin to deploy front-end assets to S3 via the Serverless Framework
JavaScript
171
star
20

serverless-websockets-plugin

Websocket support for Serverless Framework on AWS
JavaScript
149
star
21

serverless-openwhisk

Adds Apache OpenWhisk support to the Serverless Framework!
JavaScript
143
star
22

typescript

TypeScript definitions for Serverless Framework service configuration
TypeScript
140
star
23

serverless-slackbot

[Deprecated] A Serverless Module to create your own SlackBot without servers/websockets via Slash Commands
JavaScript
135
star
24

cloud

Serverless Cloud makes building, deploying, and managing serverless applications easier and more accessible to everyone.
HTML
112
star
25

compose

Orchestrate Serverless Framework in monorepos
JavaScript
109
star
26

event-gateway-example

JavaScript
104
star
27

serverless-optimizer-plugin

Serverless Optimizer Plugin: Optimizers for reducing Lambda file sizes and improving their performance -
JavaScript
102
star
28

enterprise

Documentation for the Serverless Framework Enterprise Edition –
95
star
29

multicloud

The serverless @multicloud library provides an easy way to write your serverless handlers 1 time and deploy them to multiple cloud providers include Azure & AWS.
TypeScript
90
star
30

aws-event-mocks

JavaScript
83
star
31

emulator

Serverless Emulator which lets you run serverless functions locally
JavaScript
78
star
32

serverless-local-schedule

⚡️🗺️⏰ Schedule AWS CloudWatch Event based invocations in local time(with DST support!)
JavaScript
72
star
33

event-mocks

TypeScript
72
star
34

fdk

This library is deprecated. Please use https://github.com/serverless/event-gateway-sdk instead.
JavaScript
69
star
35

serverless-open-runtime

WIP - An extensible, community-driven, open-runtime for serverless compute
Go
68
star
36

serverless-runtime-babel

Babel runtime for v.0.5 of the Serverless Framework
JavaScript
68
star
37

forms-service

Serverless Forms Service to collect form data with Admin UI
JavaScript
66
star
38

serverless-secrets-plugin

JavaScript
66
star
39

serverless-golang

Serverless Template for Golang
Go
64
star
40

serverless-tencent

⚡️ 🐧 Serverless Tencent CLI 及中文讨论社区
JavaScript
63
star
41

serverless-slack

A Serverless Module featuring pre-written Slack functions from authorization to slash commands!
JavaScript
49
star
42

dashboard-plugin

The Serverless Framework Dashboard plugin
JavaScript
49
star
43

event-gateway-getting-started

Walkthrough application for using the Event Gateway. -- https://www.serverless.com
JavaScript
48
star
44

workshop

A complete full-stack application and walkthrough for learning the features of the Serverless Framework.
CSS
45
star
45

desktop

A native GUI application that makes it easy to explore and test Serverless Framework applications built on AWS Lambda.
45
star
46

serverless-swagger-plugin

JavaScript
44
star
47

serverless-meta-sync

Secure syncing of serverless project meta data across teams
JavaScript
44
star
48

event-gateway-sdk

Event Gateway JavaScript SDK
JavaScript
43
star
49

safeguards-plugin

Serverless Framework Plugin to enforce safeguard policies
JavaScript
33
star
50

serverless-graphql-relay

Serverless GraphQL Boilerplate using Relay – Ready to be deployed to production within minutes …
JavaScript
32
star
51

utils

General serverless utilities
JavaScript
29
star
52

serverless-event-gateway-plugin

Event Gateway plugin for Serverless Framework
JavaScript
28
star
53

eslint-config

Common ESLint & Prettier config for Serverless projects
JavaScript
27
star
54

serverless-knative

Serverless Knative Provider Plugin – Adds Knative to the Serverless Framework
JavaScript
25
star
55

serverless-plugin-boilerplate

A Starter Project to help you build Plugins for the Serverless Framework -
JavaScript
24
star
56

dashboard

JavaScript
24
star
57

fullstack-course

The entire fullstack application course as seen on serverless.com/learn
JavaScript
24
star
58

serverless-babel-plugin

A Serverless plugin to compile your JavaScript code with Babel before deployment
JavaScript
23
star
59

serverless-plugin-log-retention

Control the retention of your serverless function's cloudwatch logs.
JavaScript
20
star
60

cloud-computing-conferences

A curated list of all the best cloud computing conferences happening in 2019! Check here to find a serverless or cloud event happening near you.
18
star
61

event-gateway-workshop

Learn what the Event Gateway is, how it works and build your first event-driven multi-cloud application!
JavaScript
18
star
62

fdk-tmp

The Serverless Function Development Kit (FDK)
JavaScript
18
star
63

aws-sdk-extra

The AWS SDK + a handful of extra convenience methods.
JavaScript
18
star
64

platform-sdk

Serverless Platform SDK
JavaScript
17
star
65

meetups

Want to start a Serverless usergroup? We can help you get started and be an official Serverless Usergroup. Join us to be part of the family of many Serverless Usergroups across the world.
17
star
66

boilerplate-googlecloudfunctions-nodejs

A Serverless Framework Boilerplate for Google Cloud Functions support in Node.js
JavaScript
15
star
67

cli

Serverless Components CLI
JavaScript
14
star
68

serverless-helpers-py

Python
12
star
69

tutorial

A tutorial repo with multiple projects designed to help teach users
JavaScript
11
star
70

serverless-helpers-js

Serverless Helpers Node.Js: An NPM module that provides helper functions for Serverless Modules written in Node.js -
JavaScript
11
star
71

template

Compose & provision a collection of Serverless Components
JavaScript
10
star
72

template-package

Repository template for serverless packages
JavaScript
9
star
73

serverlessconf-workshop

JavaScript
9
star
74

serverless-search-engine

Part of the Serverless Live series where we build a very simplistic search engine and spider
JavaScript
9
star
75

artwork

Official design elements of Serverless Inc. and its projects
8
star
76

extensions

Use / make / monetize developer experiences.
JavaScript
8
star
77

event-gateway-connector

Serverless Event Gateway Connector Framework
Go
7
star
78

raffleapp

A serverless raffle app
JavaScript
7
star
79

netlify-landing-page

Components Landing page demo
CSS
7
star
80

compose-example

JavaScript
6
star
81

demo-todo

An example serverless-todo app
JavaScript
5
star
82

serverless-raffle

JavaScript
5
star
83

enterprise-template

JavaScript
5
star
84

workshops

Companion repo for workshops with instructions and code examples
JavaScript
5
star
85

sls-action

GitHub action for Serverless CLI
TypeScript
5
star
86

test

Test setup and utilities for serverless projects
JavaScript
4
star
87

compose-website-example

JavaScript
4
star
88

console

4
star
89

cli-design

Repository to discuss Serverless Framework v3 redesign
HTML
4
star
90

event-gateway-tracer

JavaScript
3
star
91

core

Serverless Components Core
JavaScript
3
star
92

status

The Serverless Status Page
JavaScript
3
star
93

partner-examples

JavaScript
2
star
94

components-core

WIP
TypeScript
2
star
95

azure-build-task

A Serverless build task for Azure Dev Ops
TypeScript
1
star
96

sfe-nodejs-service

JavaScript
1
star
97

inquirer

inquirer with enforced serverless theme
JavaScript
1
star
98

template-getting-started-node-js

Application templates used by the Serverless Platform
1
star
99

serverless-cloud-gitpod

Starter repository for running Serverless Cloud on GitPod
1
star
100

user-testing

Tests of product concepts
JavaScript
1
star