Skip to content

jayramankumar/AzureFunctionsIntroduction

 
 

Repository files navigation

Branch Usage BuildStatus
master Precompile

AzureFunctionsIntroduction

This is Sample project for Azure Functions. May this repository help you understand Azure Functions better.

What you can know

This sample include following.

DirectoryName FunctionName Language Pre-compiled? Description
src AppSettingsWebhookCSharp C# Yes Reference Application Settings > App Setting of Web Apps Sample code.
src CSharpCompilerSlackOuthookCSharp C# Yes Slack C# Code Roslyn Evaluation Sample. (@C#: Enumerable.Range(10, 20).Aggregate((x, y) => x + y))
src CSharpCompilerWebhookCSharp C# Yes Generic Webhook C# Code Roslyn Evaluation Sample.
src DotNetFrameworkVersionResponseCSharp C# Yes Retrurn .NET Framework Friendly Name by passing .NET Framework Release Registry Value.
src GenericWebhookCSharpExtensionMethod C# Yes Extension Method usage Sample code.
src GithubWebhookCSharp C# Yes Github Webhook Sample code.
src LineBotWebhookCSharp C# Yes Line Bot Webhook Sample code with Emergency Evacuation info with sent info.
src PreCompiledFunctionSample C# Yes Basic sample of PreCompiled Function. Build artifact will published right under root as PreCompiledFunctionSample.
src PreCompileEnvironmentVariables C# Yes Basic sample of PreCompiled Function with Logger. Build artifact will published right under root as PreCompileEnvironmentVariables.
src SSLCertificateExpireCheck C# Yes SSL Certificate Checker. Often introduce in AWS Lambda but you can do with C# + AzureFucntions, too!
src VSTSWebhookCSharp C# Yes Visual Studio Team Service (VSTS) Webhook trigger Sample code.
src WebhookCSharpGithubOctokit C# Yes NuGet package reference sample for Octokit.
src WebhookCSharpSendToChatWork C# Yes Chatwork Notification Sample code.
src WebhookCSharpSendToSlack C# Yes Slack Notification Sample code.
CsxSamples AppSettingsWebhookCSharp C# No Reference Application Settings > App Setting of Web Apps Sample code.
CsxSamples CSharpCompilerSlackOuthookCSharp C# No Slack Interactive C# Code Roslyn Evaluation Sample. (@C#: Enumerable.Range(10, 20).Aggregate((x, y) => x + y))
CsxSamples CSharpCompilerWebhookCSharp C# No Generic Webhook C# Code Roslyn Evaluation Sample.
CsxSamples DotNetFrameworkVersionResponseCSharp C# No Retrurn .NET Framework Friendly Name by passing .NET Framework Release Registry Value.
CsxSamples ExternalCsxWebhookCSharp C# No Reference external .csx usage Sample code.
CsxSamples GenericWebhookCSharpExtensionMethod C# No Extension Method usage Sample code.
CsxSamples GithubWebhookCSharp C# No Github Webhook Sample code.
CsxSamples LineBotWebhookCSharp C# No Line Bot Webhook Sample code with Emergency Evacuation info with sent info.
CsxSamples SSLCertificateExpireCheck C# No SSL Certificate Checker. Often introduce in AWS Lambda but you can do with C# + AzureFucntions, too!
CsxSamples VSTSWebhookCSharp C# No Visual Studio Team Service (VSTS) Webhook Sample code.
CsxSamples WebhookCSharpGithubOctokit C# No NuGet package reference sample for Octokit.
CsxSamples WebhookCSharpSendToChatWork C# No Chatwork Notification Sample code.
CsxSamples WebhookCSharpSendToSlack C# No Slack Notification Sample code.

GitHub Integration Sample

You may find this repository structure is fit with Azure Functions CI by Github. This repogitory Sync with Azure Functions by GitHub Integration.

Default structure can be publish with Precompiled Functions.

If you want to use CsxSamples then replace whole root items with CsxSamples/. It allows you to deploy .csx samples by Azure Github Continuous Deployemnt.

More Reference

Reference Description
Blog post - tech.guitarrapc.com Blog post for AzureFuncitons by repository owner.
Azure/Azure-Functions AzureFunctions official repo. You may find where to report Issue, Feature Requests, Questions and Help.
Microsoft Azure WebJobs SDK Quick Reference Web Job SDK cheat sheet.

Precompiled functions reference

Refer basic information with https://github.com/Azure/azure-webjobs-sdk-script/wiki/Precompiled-functions .

Following additional tips will be useful for first step.

Description Screenshot
You can use both VS2015 Update3 and VS2017 (not preview 3) with this Repository samples. Make sure install Azure Functions Core Tools before begin.
Use precompile function when you want to gain more faster execution and IDE compile, debug benefits.
Unfortunately .csx is not yet match friendly for VS Debugging. It will not detect compile error and less intellisense at all.
Therefore you will find .csx will cause compile error on Function App portal so often. If you feel it reduce your efficiency, then use precompile instead.
Azure App Service Team Blog - Publishing a .NET class library as a Function App explain how to with Web Application project.
If you are using VS2017 update 3 .NET Web Development and Tools Blog - Visual Studio 2017 Tools for Azure Functions offer how to with latest tooling.
function.json sample.

VS ProjectSettings > Web Sample
There are several way for local debug with post/get request, LinqPad, PowerShell, curl and others. I use PostMan Chrome extensions heavily when local debugging and remote debugging.
Nuget Package reference for AzureFunctions functionality.
Microsoft.AspNet.WebApi.Core for .CreateResponse() and other HttpRequestMessage Extension method.
Install-Package Microsoft.AspNet.WebApi.Client
Install-Package Microsoft.AspNet.WebApi.Core
Microsoft.Azure.WebJobs.Host for TraceWriter Logger as like .csx using Microsoft.Azure.WebJobs.Host; at your code namespace.
Microsoft.Azure.WebJobs.Extensions for Timer trigger
Install-Package Microsoft.Azure.WebJobs.Extensions


Precompiled function's dll will be locked by w3wp.exe when deployed function. This behaiviour is fixed but need to deploy into DEPLOYMENT_TEMP beforehand.
See sample deploy in deploy.cmd
Take care about nuget restore and KUDU SYNC volume. Dynamic pricing is limited to 500MB and will easily reach to the size with precompile.
This repogitory needs 288MB for full Nuget package restore, it means total 500MB when build.
Then Deploy will COPY to DEPLOYMENT_TEMP for Shadowcopy then COPY to production location.
OK. you know what happens. I Recopment split codes for usage (Trigger, timer or other) or use Service Plan model.

Recommend Azure Functions settings for stability and efficiency

These settings are my recommendation with using AzureFunctions.

Description Screenshot
Concider to select Dynamic Service Plan if possible.
This will bring you best cost efficiency and scalability.
Keep your Azure Functions Runtime version up-to-date. Actually there's no meaning concider downtime because apply will be done in just a seconds.
Keep Function App Platform 32bit (don't change to 64bit)
Do not run out memory, add Dynamic Memory if needed! Default 128MB will be run out easiry. Upgrade to 256MB or higher as your app requires.
Dynamic Plan pricing is relates to Memory size, but less meanful to concider.
AzureFunctions pricing is here.
Make sure your functions memory comsumptions will be less than 1536MB. This is limiation of Dynamic Service Plan.
In case you exceed 1536MB there's 2 options.
- Divide to separate functions.
- Combine all functions to single App Service Plan.
Stop nesting multiple Azure Functions, use #load "<YourCoolLogic.csx>", or project reference for Precompile class library, to load shared code.
This is efficient and speedier way to call functions.

Use AppSettings to store secret values. This eliminate sensitive value in the source code.
You can load it with both System.Environment.GetEnvironmentVariable("Key") or System.Configuration.ConfigurationManager.AppSettings["Key"].
C# sample with screenShot: GetEnvironmentVariable("Secret_Value") or ConfigurationManager.AppSettings["Secret_Value"];
See C# Dev Samples for more details
appsettings.json is deprecated, use local.settings.json instead.
If using Timer Trigger, then put "{singleton": {"listenerLockPeriod": "00:00:15"}} to host.json. This avoid you from host lock issue.
Set AzureWebJobsStorage for every non Webhook Triggers.

Not Recommend

There's are possible but I never recommend. These settings will bring complexity.

Description Screenshot
Default TimeZone is UTC, but you can use LocalTime zone with WEBSITE_TIME_ZONE into Application Settings.
You can obtain all timezone string with System.TimeZoneInfo.GetSystemTimeZones()
Detail is here : Changing the server time zone on Azure Web Apps
To keep Deployment simplicity, I never recommend mix up Precompile functions and .csx functions.

License

MIT

Releases

No releases published

Packages

No packages published

Languages

  • C# 94.0%
  • Batchfile 6.0%