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
190
Introduction to Azure Functions
build 2016振り返り 勉強会のスライドです。
TonyTonyKun
December 10, 2017
Tweet
Share
More Decks by TonyTonyKun
See All by TonyTonyKun
Prompty を使って生成 AI アプリケーション開発のプロンプトを管理する/jat03
thara0402
0
9
Azure OpenAI Service で意図せず PTU モデルをデプロイして高額請求されてしまった件/jat04
thara0402
0
7
「Durable Task Scheduler」をチョイ見せ!/jat05
thara0402
0
2
Azure App Service on Linux の Sidecar に Phi-3 を配置してインテリジェントなアプリケーションを作ってみよう/jazug-anniv14
thara0402
0
1k
サイクルガードサービス AlterLock の問い合わせ対応業務に Azure OpenAI Service を活用した話/jazug46
thara0402
0
870
Microsoft Ignite 2023 現地参加レポート/ignite2023
thara0402
0
250
Azure Container Apps で .NET 7 アプリを Blue-Green デプロイしてみよう!/jazug12
thara0402
0
1.7k
Azure Synapse Analytics 入門/jazug11
thara0402
0
710
Azure Bicep で始める Infrastructure as Code/ace0917
thara0402
0
450
Other Decks in Technology
See All in Technology
表現を育てる
kiyou77
1
230
Exadata Database Service on Cloud@Customer セキュリティ、ネットワーク、および管理について
oracle4engineer
PRO
1
1.5k
エンジニアの育成を支える爆速フィードバック文化
sansantech
PRO
3
1.1k
室長と気ままに学ぶマイクロソフトのビジネスアプリケーションとビジネスプロセス
ryoheig0405
0
370
偏光画像処理ライブラリを作った話
elerac
1
130
php-conference-nagoya-2025
fuwasegu
0
110
Autonomous Database Serverless 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
17
45k
IAMポリシーのAllow/Denyについて、改めて理解する
smt7174
2
160
Amazon S3 Tablesと外部分析基盤連携について / Amazon S3 Tables and External Data Analytics Platform
nttcom
0
150
AIエージェント元年
shukob
0
120
分解して理解する Aspire
nenonaninu
2
500
ESXi で仮想化した ARM 環境で LLM を動作させてみるぞ
unnowataru
0
140
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Bash Introduction
62gerente
611
210k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
420
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
Unsuck your backbone
ammeep
669
57k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Designing Experiences People Love
moore
140
23k
Designing for Performance
lara
604
68k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Building Your Own Lightsaber
phodgson
104
6.2k
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