Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Azure Functions

Avatar for TonyTonyKun TonyTonyKun
December 10, 2017

Introduction to Azure Functions

build 2016振り返り 勉強会のスライドです。

Avatar for TonyTonyKun

TonyTonyKun

December 10, 2017
Tweet

More Decks by TonyTonyKun

Other Decks in Technology

Transcript

  1. ⾃⼰紹介 名前 Twitter : @TonyTonyKun(トニー) 仕事 C# で業務アプリケーションを開発しています。 Azure をベースに

    ASP.NET を使うことが多いです。 Blog ROMANCE DAWN for the new world http://gooner.hateblo.jp/ Copyright© 2016, JAZUG All Rights Reserved. 2
  2. さまざまな Trigger と Binding をサポート Copyright© 2016, JAZUG All Rights

    Reserved. 8 Type Service Trigger Input Output Schedule Azure Functions ✔ HTTP (REST or WebHook) Azure Functions ✔ ✔ Blob Storage Azure Storage ✔ ✔ ✔ Queues Azure Storage ✔ ✔ Queues Azure Service Bus Queue ✔ ✔ Topics Azure Service Bus Topic ✔ ✔ Tables Azure Storage ✔ ✔ Tables Azure Mobile Apps Easy Tables ✔ ✔ No-SQL DB Azure DocumentDB ✔ ✔ Streams Azure Event Hubs ✔ ✔ Push Notifications Azure Notification Hubs ✔
  3. 複数の開発⾔語をサポート メイン C# Node / JavaScript その他(⼀部の Trigger や Binding

    のみ対応) F# Python PHP Batch Bash PowerShell Copyright© 2016, JAZUG All Rights Reserved. 9
  4. 2つの課⾦モデル Dynamic App Service Plan 実⾏した分だけ課⾦される リクエスト数(100 万単位) サーバーレスアーキテクチャらしいモデル Classic

    App Service Plan 従来の課⾦モデル(Free, Basic, Standard, Premium) Web Apps にデプロイしたアプリと共存させるときに使う Functions ⾃体には課⾦されない、Web Jobs に近いイメージ Copyright© 2016, JAZUG All Rights Reserved. 10
  5. Azure App Service に追加されたサービス Web Jobs を拡張したサービス 実⾏環境は Web Apps

    なので、同じ機 能が使える App Settings Connection Strings Kudu / Site Extension Remote Debug 便利かつ⾃由度の⾼いサービス Copyright© 2016, JAZUG All Rights Reserved. 11
  6. 外部アセンブリの参照 よく使う .NET のアセンブリは、⾃動的に参照されている System.Net.Http.dll Microsoft.Azure.WebJobs.dll など 必要に応じて、#r “AssemblyName” で参照できる

    Newtonsoft.Json.dll のように、.NET に含まれていなくても、使えるア センブリもある プライベート アセンブリは、bin フォルダにアップロードする “D:¥home¥site¥wwwroot¥{function name}¥bin” に配置する #r “MyAssembly.dll“ で参照できる Copyright© 2016, JAZUG All Rights Reserved. 15
  7. Demo App Settings から値を取得する System.Configuration の using を追加する プライベートアセンブリを参照する NuGet

    Package から Jil Json Serializer を参照する https://github.com/kevin-montrose/Jil .csx ファイルのコードを再利⽤する Copyright© 2016, JAZUG All Rights Reserved. 18
  8. Azure Portal の Advanced Editor Copyright© 2016, JAZUG All Rights

    Reserved. 22 function.json を編集できるので、詳細な構成ができる
  9. HTTP Trigger https://{site name}.azurewebsites.net/api/{function name} name .csx のコードで使う変数名 authLevel Function:Function

    Key admin:Master Key anonymous:認証なし Copyright© 2016, JAZUG All Rights Reserved. 23
  10. API Key HTTP Trigger と WebHook Trigger で API Key

    を要求できる クエリ⽂字列:code HTTP ヘッダー:x-functions-key API Key ⾃体は、D:¥home¥data¥Functions¥secrets に定義されている Function Key 無効なファンクションはトリガーできない ファンクションごと or 共通の API Key Master Key 無効なファンクションもトリガーできる すべてのファンクションで共通の API Key Copyright© 2016, JAZUG All Rights Reserved. 25
  11. Azure Storage Queue Trigger Copyright© 2016, JAZUG All Rights Reserved.

    26 引数へのバインド string byte[] JObject CloudQueueMessage など myqueue-items
  12. Azure Storage Queue Output Binding Copyright© 2016, JAZUG All Rights

    Reserved. 27 引数へのバインド string byte[] JObject CloudQueueMessage ICollector<T> など outqueue
  13. Azure Storage Blob Input Binding Copyright© 2016, JAZUG All Rights

    Reserved. 28 引数へのバインド string Stream JObject CloudBlockBlob など incontainer
  14. Timer Trigger {second} {minute} {hour} {day} {month} {day of the

    week} 6つのフィールドを含む CRON 式 {second} フィールドを省略してはダメ hh:mm:ss 形式も可能 タイムゾーンは UTC で指定する runOnStartup すぐに実⾏するかどうか Copyright© 2016, JAZUG All Rights Reserved. 30
  15. Timer Trigger 10分ごとに実⾏する場合 すぐに実⾏し、毎⽇0時(JST)に実⾏する場合 ⽉曜から⾦曜の17時(JST)に実⾏する場合 Copyright© 2016, JAZUG All Rights

    Reserved. 31 "schedule": "0 */10 * * * *“ "schedule": "0 0 15 * * * “ "runOnStartup": true "schedule": "0 0 8 * * 1-5“ "schedule": "00:10:00“
  16. 参考資料 Azure Functions の概要 https://azure.microsoft.com/ja-jp/documentation/articles/functions- overview/ Introducing Azure Functions https://channel9.msdn.com/Events/Build/2016/B858

    Azure Functions Under the Hood https://channel9.msdn.com/Events/Build/2016/T692 オープンソース https://github.com/azure/azure-webjobs-sdk-script Copyright© 2016, JAZUG All Rights Reserved. 34