Azure Functions:

Serverless development concepts

Lansing DevOps Meetup
June 5th, 2018

Brendon Thiede

  • DevOps Engineer at the Michigan Supreme Court
  • Focused on Automation
  • Linux and Java for the last decade
Overload

Now I am assimilated...

Topics

  • Azure ARM Template
  • Runtime/Framework version compatibility
  • Build definition/Deployment
  • Function annotations
  • Bindings
  • Dependency Injection
  • Demo

Function Infrastructure

  • App Service Plan (Consumption or Dedicated)
  • App Service (Function type)
    • Application Settings (Environment Variables)
  • Storage Account
  • Application Insights (Optional)

Function Runtime

  • 1.x - Fully Supported
  • 2.x - Beta

Language

  • C# (Precompiled class library or script)
    • .NET Framework 4.6
    • .NET Standard
  • JavaScript
  • F#

More at: https://docs.microsoft.com/en-us/azure/azure-functions/supported-languages

My Secret Sauce

  • .NET Standard 2.0
  • Precompiled
  • 2.x (Beta) Function Runtime
  • Consumption Plan

Build Process

  • Validate ARM template
  • Publish ARM template
  • dotnet test
  • dotnet publish
  • Publish artifact

Deployment Process

  • New-AzureRmResourceGroupDeployment ...
  • az functionapp deployment source config-zip ...

Function Annotations

Specify function name:


[FunctionName("DevHealthCheckScheduler")]
                

Disable function:


[Disable("DISABLE_SCHEDULERS")]
                

Pro

Very flexible structure

Con

Magic strings with no* IDE support

Bindings


[FunctionName("DevHealthCheckScheduler")]
[Disable("DISABLE_SCHEDULERS")]
public static void Run(
    [TimerTrigger("%DevHealthCheckSchedulerCronExpression%")] TimerInfo myTimer,
    [OrchestrationClient] DurableOrchestrationClient starter)
{
    starter.StartNewAsync("Orchestrators_HealthCheckMasterOrchestrator", "dev");
}
                

Binding Types

Dependency Injection


[FunctionName("Activities_HealthChecker")]
public static AppEnvStatus GetHealthCheckStatus(
    [ActivityTrigger] HealthCheckEndpoint healthCheckEndpoint,
    [Table("AppEnvStatuses")] CloudTable appEnvStatuses)
{
    using (HttpClient httpClient = new HttpClient())
    {
        AppEnvStatus appEnvStatus = SlackBotUtils.RetrieveAppEnvStatus(healthCheckEndpoint, appEnvStatuses);
        appEnvStatus.LatestStatus = AppEnvStatus.FAILURE;
        appEnvStatus.LatestStatusTimeStamp = DateTime.Now;

        RequestHealthCheckEndpoint(healthCheckEndpoint, appEnvStatuses, httpClient, appEnvStatus);

        return appEnvStatus;
    }
}

Function Chaining

  • Output binding -> Function trigger
  • Durable Functions

Cost Comparison

  • Manual queue based chaining: $0.06/day, $1.90/month
  • Durable Function orchestration: $0.18/day, $5.47/month
  • Storage I/O ~ 90% of cost

Demo