Quickstart Tutorial

Creating Your First Funcy Azure Project

Let's start by creating our first Funcy Azure project on Azure!

If you haven't done so already, please create your service principal credentials as outlined in Configuring Azure. You'll need them to let Funcy Azure do the provisioning and configuring of resources on your behalf.

Creating a Project Scaffold

$ faz project create -n MyProjectName -t <tenant-id> -a <app-id> -p <password> -s <subscription-id>

This will create a new project folder with a basic structure as discussed in Deep Dive - Project Structure.

πŸ“˜

Good to know

  • Note that only the name (-n, --name) parameter is actually required. You can manually edit the admin.env file and enter your service principal credentials later.

  • Same with the location of your Git repository (-l, --location). Simply edit f-project.json.

  • Also keep in mind that you can change the name of the project any time by editing the field name in f-project.json. This might be necessary in case your project name has already been taken by someone else on Azure (in which case Funcy Azure throws an exception during provisioning).

Every subsequent command in this chapter assumes that you are in the root folder of your project.

So please $ cd MyProjectName before you proceed.

Creating a Function Scaffold

$ faz function create MyFirstFunction -n MyFirstFunction -e http

This creates an http-triggered function which can be invoked through an HTTPS endpoint. In the newly created folder MyFirstFunction/ you will find three files:

  • args.json: here you can enter sample event parameters that will be passed to your function when executed locally.
  • function.json: contains the binding definitions, that is, in and out parameters.
  • index.js: your function code.

Running your function locally

Now that we have created a function, let's run it locally!

$ faz function emulate -n MyFirstFunction
[LOG] Node.js HTTP trigger function processed a request. RequestUri=localhost
SUCCESSFUL EXECUTION!
OUTPUT BINDINGS:
res: {
    "status": 400,
    "body": "Please pass a name on the query string or in the request body"
}

Cool, that seems to work! As you can see, log messages printed via context.log are displayed with a [LOG] prefix. Every output binding configured in function.json is also displayed at the end of the local test run (which is "res" in this case).

But how can we pass input parameters to our function? This is what args.json is for. Modify it as follows:

{
	"bindings": {
    "req": {
      "query": {
        "name": "Funcy Azure"
      }
    }
  }
}

... and run it again:

$ faz function emulate -n MyFirstFunction
[LOG] Node.js HTTP trigger function processed a request. RequestUri=localhost
SUCCESSFUL EXECUTION!
OUTPUT BINDINGS:
res: {
    "body": "Hello, Funcy Azure"
}

Well, that seemed to work!

πŸ“˜

Good to know

  • Funcy Azure currently supports the following event types: http, blob, eventhub, timer and queue

  • Properties passed to context.done overwrite according out bindings. See https://azure.microsoft.com/en-us/documentation/articles/functions-reference-node/ for more information.

  • "In"-Bindings are passed to your function in the same order as they have been defined in function.json and are initialized as defined in args.json

  • Data written to out bindings does not get written to the actual target (for instance to blob storage).

Deploying and Provisioning to Azure

Funcy Azure manages the provisioning of resources your application needs to run on Azure. It does not, however, directly manage your code deployments. This is accomplished through Git integration. So before we provision to Azure, let's first integrate the project with a Git repository.

Setting up Continuous Integration with a Git Repository

Currently, we support integration with two kinds of Git repositories: Github repositories and Function App repositories (hosted on Azure, automatically associated with your Function app). We will discuss how to configure both kinds in subsequent sections.

Gitub Repository

Create a new remote Git repository on Github.

Initialize a new local Git repository in your project's root folder, add all files, commit and push to the remote repository you have just created:

$ git init && git add . && git commit -a;
$ git remote add origin https://<path.to.repository>
$ git push -u origin master

Now simply add the repository path to your f-project.json file (under versionControl) and change the branch if applicable.

{
  ...
  "versionControl": {
    "type": "git",
    "location": "https://github.com/repositoryname.git",
    "branch": "master"
  }
  ...
}

Function App Repository

Be sure to enable your local Git repository by defining a Git username and password (aka deployment username and deployment password) in the Azure portal. See https://azure.microsoft.com/en-us/documentation/articles/web-sites-publish-source-control/ for details.

Initialize a new local Git repository in your project's root folder, add all files, commit and push to the repository you have just created:

$ git init && git add . && git commit -a;
$ git remote add origin https://<username>@.scm.azurewebsites.net:443/<projectname>.git
$ git push -u origin master

Last thing you need to do is to let Funcy Azure know that you would like to use Continuous Intergration with your Function App repository. Change f-project.json as follows:

{
  ...
  "versionControl": {
    "type": "git",
    "location": "local",
    "branch": "master"
  }
  ...
}

πŸ“˜

Good to know

  • You can also integrate with Git at a later point in time. In this case just leave the location field empty. If you provision, though, only the Azure resources (Function App, Web App Plan) will be provisioned and configured, no function code will be deployed.

  • Per default, IsManualIntegration in the ARM-Template f-resources-arm.json is set to true. This means, that Azure will not automatically re-deploy your code you are pushing to Git again. You have to explicitly grant Azure access to your Github account by entering your Github credentials in the portal. Once you have done this, you can set the flag to false in the ARM-Template and then re-provision to enable the new setting.

Deploying your project to Azure

In order to finally deploy your application to Azure, execute the following command:

$ faz project provision -g FAZ-RG -l westeurope -f FAZ-WebPlan
Starting provisioning / updating your project... (this may take up to ~3 mins)

Creating / Updating Resource Group... DONE!
Validating ARM template... DONE!
Executing ARM template... DONE!
******************************************************************
All good. Your project has been successfully provisioned to Azure.

You need to provide three parameters:

  • -g : the name of the resource group you want to deploy your application in. If it does not exists already, it is created for you.
  • -l the location you want your application to run in. To see in which regions Azure Functions are currently availabe, please take a look at https://azure.microsoft.com/en-us/regions/#services
  • -s the name of the web plan your application should (re-)use. If it does not exist yet, it is created for you.

πŸ“˜

Good to know

Getting the Function Endpoint

Great, now everything should be provisioned, configured and deployed on Azure. But how do you find out the HTTPS-endpoints of your deployed functions?
Funcy Azure provides a dedicated command for this purpose. To get all HTTP-endpoints simply type (or provide a specific function name after the -n parameter):

$ faz function endpoint -n "*" -g FAZ-RG
Function deployment info in resource group FAZ-RG:
MyFirstFunction
 |__https://myprojectname.azurewebsites.net/api/myfirstfunction?code=lHNp8NFtUdJAhZ61vc5Q5Jcd9FFplpJtvOdY3HfC14l6xc4wgSaa5g==

No put this link in a browser, append &name=azure, and watch the magic happen. The great thing is, if nobody is calling your function, you are not paying a cent. This is true pay-per-use.

Congratulations! You have successfully completed this tutorial. Now go build amazing things with Funcy Azure and Azure Functions!