Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Azure Functionsで始めるサーバーレス アーキテクチャ
Search
TonyTonyKun
December 10, 2017
Technology
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Azure Functionsで始めるサーバーレス アーキテクチャ
JAZUG 6周年総会のセッション資料です。
TonyTonyKun
December 10, 2017
More Decks by TonyTonyKun
See All by TonyTonyKun
Azure Durable Functions で作った NL2SQL Agent の精度向上に取り組んだ話/aidevday2026
thara0402
0
410
Azure Static Web Apps の自動ビルドがタイムアウトしやすくなった状況に対応した件/global-azure2026
thara0402
0
860
Azure Durable Functions で作った NL2SQL Agent の精度向上に取り組んだ話/jat08
thara0402
0
450
これでバッチリ!Azure マルチテナントアーキテクチャ設計のコツ/jat06
thara0402
0
790
Azure Load Testing を使って Azure Functions Flex Consumption の HTTP Trigger のパフォーマンスとコストを最適化してみよう/global-azure2025
thara0402
0
380
Prompty を使って生成 AI アプリケーション開発のプロンプトを管理する/jat03
thara0402
0
97
Azure OpenAI Service で意図せず PTU モデルをデプロイして高額請求されてしまった件/jat04
thara0402
0
110
「Durable Task Scheduler」をチョイ見せ!/jat05
thara0402
0
77
Azure App Service on Linux の Sidecar に Phi-3 を配置してインテリジェントなアプリケーションを作ってみよう/jazug-anniv14
thara0402
0
1.5k
Other Decks in Technology
See All in Technology
Genieを崇めよ
kameitomohiro
0
170
Railsのように考える: See through the Master
snoozer05
PRO
4
1.2k
LLMに渡さなかった仕事
nanaism
0
1k
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
5
25k
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
2.1k
ADKで始める業務改善 - AIエージェント開発時の考えと設計
harappa80
2
240
Issue 駆動でスペシャリストの意図を届ける、AI 実装のアクセシビリティ向上
thkt
0
120
What the customer really needed
kawaguti
PRO
3
210
データ界隈LT祭 第1回LT登壇
taromatsui_cccmkhd
2
1.5k
「守り」で活用するオンデバイスLLM 〜写ってはいけないを総力戦で防ぐ〜 / iOSDC Japan 2026
nakamuuu
0
180
その Lambda、8分で 管理者権限まで奪われます
k1nakayama
6
3.2k
AIエージェントを最高のパートナーに育てる方法|評価と判断軸を育てる5つのステップ
koichiaoki
1
150
Featured
See All Featured
Believing is Seeing
oripsolob
1
220
Navigating Weather and Climate Data
rabernat
0
520
Designing Experiences People Love
moore
143
24k
It's Worth the Effort
3n
188
29k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
730
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
BBQ
matthewcrist
89
10k
Google's AI Overviews - The New Search
badams
0
1.6k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
Deep Space Network (abreviated)
tonyrice
0
310
Transcript
Azure Functions で始める サーバーレス アーキテクチャ 2016.09.03 JAZUG 6周年総会
⾃⼰紹介 名前 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/09/03 時点の情報を基にしています。 まだ Public Preview です。(Runtime Version 0.5) 最新情報は
Web で。 Copyright© 2016, JAZUG All Rights Reserved. 3
Goal Azure Functions の機能をざっくりと知る Azure Functions の使いどころが分かる Copyright© 2016, JAZUG
All Rights Reserved. 4
What is Serverless? 最近よく聞く話題だけど・・・ Copyright© 2016, JAZUG All Rights Reserved.
5
Serverless Architectures (Martin FowlerのBlog) Backend as a Service Single Page
Application なアプリやモバイルアプリから利⽤するクラウド上の バックエンドサービス(ストレージや認証とか) Function as a Service ⾃分で書いたコードがイベント駆動で実⾏されるステートレスなサービス 発端は、AWS の Lambda がリリースされたこと その後、他のクラウドベンダーも相次いでリリースしたサーバーレス 環境は、後者の FaaS のこと Google の Cloud Functions IBM の OpenWhisk Microsoft の Azure Functions Copyright© 2016, JAZUG All Rights Reserved. 6 http://martinfowler.com/articles/serverless.html
What is Serverless Computing? Exploring Azure Functions. ( Scott Hanselman
のBlog ) サーバーレスとは、サーバーがないという意味ではない ⾃分でサーバーを管理する必要がないということ PaaS のように聞こえるかもしれないけど、それよりも⾼いレベル PaaS は Web アプリをデプロイして、常にサーバーを意識するけど、サー バーレスは、コードをアップロードし、イベント駆動で実⾏される Copyright© 2016, JAZUG All Rights Reserved. 7 http://www.hanselman.com/blog/WhatIsServerlessComputingExploringAzureFunctions.aspx https://blogs.msdn.microsoft.com/visualstudio_jpn/2016/09/01/whatisserverlesscomputingexploringazurefunctions/
Azure Functions Overview 概要と特徴 Copyright© 2016, JAZUG All Rights Reserved.
8
Azure Functions とは? サーバーレスアーキテクチャ サーバーの構築や保守は必要ない API を公開するだけのためにアプリを作る必要がない 運⽤や課⾦のコストを節約できる イベント駆動型サービス トリガーが発⽕したときだけ処理が実⾏される
Copyright© 2016, JAZUG All Rights Reserved. 9
ブラウザで簡単にコードが書ける Copyright© 2016, JAZUG All Rights Reserved. 10
さまざまな Trigger と Binding をサポート① Copyright© 2016, JAZUG All Rights
Reserved. 11 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 ✔
さまざまな Trigger と Binding をサポート② Copyright© 2016, JAZUG All Rights
Reserved. 12 Type Service Trigger Input Output SaaS File BOX ✔ ✔ Dropbox ✔ ✔ FTP ✔ ✔ Google Drive ✔ ✔ One Drive (for Business) ✔ ✔ SFTP ✔ ✔ SaaS Table DB2 ✔ ✔ Dynamics CRM Online ✔ ✔ Excel ✔ ✔ Google Sheets ✔ ✔ Informix ✔ ✔
さまざまな Trigger と Binding をサポート③ Copyright© 2016, JAZUG All Rights
Reserved. 13 Type Service Trigger Input Output SaaS Table Salesforce ✔ ✔ SharePoint ✔ ✔ SQL Server ✔ ✔ Mail SendGrid ✔ SMS Twilio ✔
複数の開発⾔語をサポート メイン C# Node / JavaScript その他(⼀部の Trigger や Binding
のみ対応) F# Python PHP Batch Bash PowerShell Copyright© 2016, JAZUG All Rights Reserved. 14
2つの課⾦モデル Dynamic App Service Plan メモリサイズ(GB単位) × 実⾏時間(秒単位) 実⾏回数 毎⽉無料枠があって、それを超えると課⾦される
サーバーレスアーキテクチャらしいモデル 最近、⽇本のデータセンターでも使えるようになった Classic App Service Plan 従来の課⾦モデル(Free, Basic, Standard, Premium) Web Apps にデプロイしたアプリと共存させるときに使う Functions ⾃体には課⾦されない、Web Jobs に近いイメージ Copyright© 2016, JAZUG All Rights Reserved. 15
モニタリングとログ Invocation Log Copyright© 2016, JAZUG All Rights Reserved. 16
モニタリングとログ Live Event Stream Azure Web Apps のサポートツールと同じ仕組み https://support-bay.scm.azurewebsites.net/Support.functionsmetrics/#/{site name}/{function
name} Copyright© 2016, JAZUG All Rights Reserved. 17
Azure App Service に追加されたサービス Web Jobs を拡張したサービス 実⾏環境は Web Apps
なので、同じ機 能が使える App Settings Connection Strings Advanced Tools / App Service Editor Remote Debug 便利かつ⾃由度の⾼いサービス Copyright© 2016, JAZUG All Rights Reserved. 18
Demo Hello world 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
Blob Trigger を利⽤する際の注意事項 トリガーが監視する Blob コンテナに10,000を超える Blob が含 まれる場合は、リアルタイムに発⽕しないことがある 数分またはそれ以上経過しないとトリガーされない可能性あり
すべてのイベントがキャプチャされる保証はない トリガーのリアルタイム性と信頼性の制限が許容できない場合 は、Queue トリガーと組み合わせることを推奨している Copyright© 2016, JAZUG All Rights Reserved. 29 https://azure.microsoft.com/ja-jp/documentation/articles/functions-bindings-storage/ https://feedback.azure.com/forums/355860-azure-functions/suggestions/13282098-should-be- support-real-time-storage-blob-triggers
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“
How .csx works .NET Compiler Platform Scripting API Copyright© 2016,
JAZUG All Rights Reserved. 32
名前空間のインポート よく使う名前空間は、⾃動的にインポートされている System.Linq Microsoft.Azure.WebJobs など 必要に応じて、using を追加する Copyright© 2016, JAZUG
All Rights Reserved. 33
アプリケーション設定の取得 環境変数から取得することが可能 パスワードなどはコードに埋め込まない ConfigurationManager.AppSettings[“key”] でも可能 Copyright© 2016, JAZUG All Rights
Reserved. 34
外部アセンブリの参照 よく使う .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. 35
NuGet ライブラリの参照 project.json ファイルをアップロードする ランタイムがパッケージを取得し、アセンブ リに参照が⾃動的に追加される #r “AssemblyName” を追加する必要はない using
を追加するだけでOK アップロードする⽅法 App Service Editor ( Visual Studio Online ) Advanced Tools ( Kudu ) FTP Copyright© 2016, JAZUG All Rights Reserved. 36
.csx コードの再利⽤ 別の .csx ファイルで定義されたコードを利⽤できる # load で .csx ファイルの相対パスを指定する
#load "myhelper.csx“ #load "..¥myhelper.csx" Copyright© 2016, JAZUG All Rights Reserved. 37
Conclusion まとめ Copyright© 2016, JAZUG All Rights Reserved. 38
まとめ サーバーレス アーキテクチャを活⽤していこう トリガーが発⽕したときのロジックだけに集中できる 1つの API のためにアプリを作ってデプロイする必要なし 運⽤や課⾦のコストを節約できる Feedback は、こちらへ
https://feedback.azure.com/forums/355860-azure-functions Copyright© 2016, JAZUG All Rights Reserved. 39
参考資料 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 Azure Functions overview and under the hood https://channel9.msdn.com/Events/de-code/2016/DEV-017 https://buchizo.wordpress.com/2016/06/04/azure-functions-overview-and-under- the-hood/ オープンソース https://github.com/azure/azure-webjobs-sdk-script Copyright© 2016, JAZUG All Rights Reserved. 40