Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Azure Functions
Search
TonyTonyKun
December 10, 2017
Technology
0
250
Introduction to Azure Functions
build 2016振り返り 勉強会のスライドです。
TonyTonyKun
December 10, 2017
Tweet
Share
More Decks by TonyTonyKun
See All by TonyTonyKun
これでバッチリ!Azure マルチテナントアーキテクチャ設計のコツ/jat06
thara0402
0
580
Azure Load Testing を使って Azure Functions Flex Consumption の HTTP Trigger のパフォーマンスとコストを最適化してみよう/global-azure2025
thara0402
0
180
Prompty を使って生成 AI アプリケーション開発のプロンプトを管理する/jat03
thara0402
0
51
Azure OpenAI Service で意図せず PTU モデルをデプロイして高額請求されてしまった件/jat04
thara0402
0
56
「Durable Task Scheduler」をチョイ見せ!/jat05
thara0402
0
38
Azure App Service on Linux の Sidecar に Phi-3 を配置してインテリジェントなアプリケーションを作ってみよう/jazug-anniv14
thara0402
0
1.3k
サイクルガードサービス AlterLock の問い合わせ対応業務に Azure OpenAI Service を活用した話/jazug46
thara0402
0
940
Microsoft Ignite 2023 現地参加レポート/ignite2023
thara0402
0
300
Azure Container Apps で .NET 7 アプリを Blue-Green デプロイしてみよう!/jazug12
thara0402
0
1.8k
Other Decks in Technology
See All in Technology
小学4年生夏休みの自由研究「ぼくと Copilot エージェント」
taichinakamura
0
530
PLaMo2シリーズのvLLM実装 / PFN LLM セミナー
pfn
PRO
2
1k
社内報はAIにやらせよう / Let AI handle the company newsletter
saka2jp
8
1.2k
Access-what? why and how, A11Y for All - Nordic.js 2025
gdomiciano
1
120
SwiftUIのGeometryReaderとScrollViewを基礎から応用まで学び直す:設計と活用事例
fumiyasac0921
0
150
関係性が駆動するアジャイル──GPTに人格を与えたら、対話を通してふりかえりを習慣化できた話
mhlyc
0
130
20201008_ファインディ_品質意識を育てる役目は人かAIか___2_.pdf
findy_eventslides
2
560
「AI駆動PO」を考えてみる - 作る速さから価値のスループットへ:検査・適応で未来を開発 / AI-driven product owner. scrummat2025
yosuke_nagai
3
760
Large Vision Language Modelを用いた 文書画像データ化作業自動化の検証、運用 / shibuya_AI
sansan_randd
0
130
AIAgentの限界を超え、 現場を動かすWorkflowAgentの設計と実践
miyatakoji
1
160
from Sakichi Toyoda to Agile
kawaguti
PRO
1
100
Goに育てられ開発者向けセキュリティ事業を立ち上げた僕が今向き合う、AI × セキュリティの最前線 / Go Conference 2025
flatt_security
0
360
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
Code Reviewing Like a Champion
maltzj
525
40k
A Tale of Four Properties
chriscoyier
160
23k
Designing for Performance
lara
610
69k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
285
14k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
2.7k
Embracing the Ebb and Flow
colly
88
4.8k
Facilitating Awesome Meetings
lara
56
6.6k
Speed Design
sergeychernyshev
32
1.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
Transcript
Introduction to Azure Functions 2016.05.21 //build/ 2016 振り返り 勉強会
⾃⼰紹介 名前 Twitter : @TonyTonyKun(トニー) 仕事 C# で業務アプリケーションを開発しています。 Azure をベースに
ASP.NET を使うことが多いです。 Blog ROMANCE DAWN for the new world http://gooner.hateblo.jp/ Copyright© 2016, JAZUG All Rights Reserved. 2
⼤事なお知らせ このセッションは、2016/05/21 時点の情報を基にしています。 まだ Public Preview です。 最新情報は Web で。
Copyright© 2016, JAZUG All Rights Reserved. 3
Goal Azure Functions の概要を知る イベント駆動型サービスの作り⽅が分かる Copyright© 2016, JAZUG All Rights
Reserved. 4
Azure Functions Overview 概要と特徴 Copyright© 2016, JAZUG All Rights Reserved.
5
Azure Functions とは? イベント駆動型サービス トリガーが発⽕したときだけ処理が実⾏される サーバーレスアーキテクチャ サーバーの構築や保守は必要ない API を公開するだけのためにアプリを作る必要がない 運⽤や課⾦のコストを節約できる
Azure 以外でも同様のサービスが提供されている AWS Lambda Google Cloud Functions など Copyright© 2016, JAZUG All Rights Reserved. 6
ブラウザで簡単にコードが書ける Copyright© 2016, JAZUG All Rights Reserved. 7
さまざまな 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 ✔
複数の開発⾔語をサポート メイン C# Node / JavaScript その他(⼀部の Trigger や Binding
のみ対応) F# Python PHP Batch Bash PowerShell Copyright© 2016, JAZUG All Rights Reserved. 9
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
Azure App Service に追加されたサービス Web Jobs を拡張したサービス 実⾏環境は Web Apps
なので、同じ機 能が使える App Settings Connection Strings Kudu / Site Extension Remote Debug 便利かつ⾃由度の⾼いサービス Copyright© 2016, JAZUG All Rights Reserved. 11
Demo Hello world Copyright© 2016, JAZUG All Rights Reserved. 12
How .csx works .csx ファイルの仕組み Copyright© 2016, JAZUG All Rights
Reserved. 13
名前空間のインポート よく使う名前空間は、⾃動的にインポートされている System.Linq Microsoft.Azure.WebJobs など 必要に応じて、using を追加する Copyright© 2016, JAZUG
All Rights Reserved. 14
外部アセンブリの参照 よく使う .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
NuGet ライブラリの参照 project.json ファイルをアップロードする ランタイムがパッケージを取得し、アセンブ リに参照が⾃動的に追加される #r “AssemblyName” を追加する必要はない using
を追加するだけでOK アップロードする⽅法 Visual Studio Online ( Monaco ) Kudu FTP Copyright© 2016, JAZUG All Rights Reserved. 16
.csx コードの再利⽤ 別の .csx ファイルで定義されたコードを利⽤できる # load で .csx ファイルの相対パスを指定する
#load "myhelper.csx“ #load "..¥myhelper.csx" Copyright© 2016, JAZUG All Rights Reserved. 17
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
Continuous Integration ポータルからは、コードを編集できなくなります Copyright© 2016, JAZUG All Rights Reserved. 19
Trigger & Bindings トリガーとバインディングの構成 Copyright© 2016, JAZUG All Rights Reserved.
20
簡単に管理できるけど、⼀部の項⽬しか構成できない Azure Portal の Standard Editor Copyright© 2016, JAZUG All
Rights Reserved. 21
Azure Portal の Advanced Editor Copyright© 2016, JAZUG All Rights
Reserved. 22 function.json を編集できるので、詳細な構成ができる
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
WebHook Trigger https://{site name}.azurewebsites.net/api/{function name} name .csx のコードで使う変数名 webHookType genericJson
Github API Key 認証は必須 Copyright© 2016, JAZUG All Rights Reserved. 24
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
Azure Storage Queue Trigger Copyright© 2016, JAZUG All Rights Reserved.
26 引数へのバインド string byte[] JObject CloudQueueMessage など myqueue-items
Azure Storage Queue Output Binding Copyright© 2016, JAZUG All Rights
Reserved. 27 引数へのバインド string byte[] JObject CloudQueueMessage ICollector<T> など outqueue
Azure Storage Blob Input Binding Copyright© 2016, JAZUG All Rights
Reserved. 28 引数へのバインド string Stream JObject CloudBlockBlob など incontainer
Demo Azure Storage Account Replication セカンダリのクールストレージにブロブをコピーする https://blogs.msdn.microsoft.com/cloud_solution_architect/2016/05/09/az ure-storage-account-backup-azure-automation-runbook-azure-functions/ Copyright© 2016,
JAZUG All Rights Reserved. 29
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
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“
Conclusion まとめ Copyright© 2016, JAZUG All Rights Reserved. 32
まとめ イベント駆動サービスを活⽤していこう トリガーが発⽕したときのロジックだけに集中できる 1つの API のためにアプリを作ってデプロイする必要なし 運⽤や課⾦のコストを節約できる Feedback は、こちらへ https://feedback.azure.com/forums/355860-azure-functions
Copyright© 2016, JAZUG All Rights Reserved. 33
参考資料 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