狠狠撸

狠狠撸Share a Scribd company logo
Azure で Serverless
初心者向けタッチ&トライ(公開版)
2019.5.29 @de:code 2019
Serverless Community
厂别谤惫别谤濒别蝉蝉とは?
Azure で Serverless 初心者向けタッチ&トライ
Azure Functions
...?
Durable Functions
? Azure Functions extension
? Enables long-running, stateful serverless operations
? Write complex function orchestrations in a single function
? Built on the open-source Durable Task Framework
? Only pay when your code is running
? Orchestrator replays itself to re-establish state every run
Durable Patterns
Function chaining Fan-out / fan-in
Event aggregation
Extended Status Monitoring
http
Async HTTP APIs
Human interaction / timeout
タッチ&トライ
作成するもの
Orchestration Client
(HttpStart)
Orchestrator
(OrchestratorFunction)
Activity Function
(E1_SayHello)
流れ
1. Visual Studio Code にAzure Functions 拡張機能をインストール
2. Azure Functions プロジェクトを作成
3. Durable Functions npm パッケージをインストール
4. starter 関数を作成
5. オーケストレーター関数を作成する
6. アクティビティ関数を作成する
7. Azure へのサインイン
8. Azure にプロジェクトを発行
9. Azure で関数をテスト
1. Azure Functions 拡張機能をインストール
? Visual Studio Code で [拡張機能] を開き、azure functions を検索するか、Visual
Studio Code でこのリンクを開きます。
? [インストール] を選択して、Visual Studio Code に拡張機能をインストールします。
? Visual Studio Code を再起動し、アクティビティ バーの Azure アイコンを選択しま
す。 サイド バーに Azure Functions 領域が表示されます。
1. Azure Functions 拡張機能をインストール
? Visual Studio Code で、Azure ロゴを選択して [Azure:Functions] 領域を表示し、[新し
いプロジェクトの作成] アイコンを選択します。
? プロジェクト ワークスペースの場所としてデスクトップの「 demo 」のフォルダを選択
し、[選択] をクリックします。
2. Azure Functions プロジェクトを作成
? 関数アプリ プロジェクトの言語は「JavaScript」を選択します。
? 「V2」を選択します。
? 「Skip for now」を選択します。
2. Azure Functions プロジェクトを作成
? 「Open in current window」を選択します。
2. Azure Functions プロジェクトを作成
3. Durable Functions npm パッケージをインストール
? VS Codeでターミナルを開き、ワークスペース用のフォルダ「demo」で「npm install
durable-functions」 を実行して、durable-functions npm パッケージをインストール
します。
※npmがインストールされていない場合は、事前にnpmをPCにインストールします
4. starter 関数を作成
? [Azure:Functions] で [関数の作成] アイコンを選択します。
? 関数アプリ プロジェクトが含まれたフォルダーを選択し、[HTTP trigger] 関数テンプレート
を選択します。
? 関数名として「HttpStart」と入力して Enter キーを押し、[Anonymous] 認証を選択します。
4. starter 関数を作成
? index.js を以下の JavaScript に置き換えます。
const df = require("durable-functions");
module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req, instanceId);
};
4. starter 関数を作成
? function.json を以下の JavaScript に置き換えます。
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": ["get", "post"]
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in"
}
]
}
Orchestration Client
(HttpStart)
Orchestrator
(OrchestratorFunction)
Activity Function
(E1_SayHello)
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": ["get", "post"]
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": ”in"
}
]
}
const df = require("durable-functions");
module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName,
undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req,
instanceId);
};
index.js
function.json
5. オーケストレーター関数を作成
? 前の手順を繰り返し、HTTP Trigger Templateを使用して 2 つ目の関数を作成しま
す。 今回は関数に 「 OrchestratorFunction」 と名前を付けます。
? index.js を以下の JavaScript に置き換えます。
const df = require("durable-functions");
module.exports = df.orchestrator(function*(context){
context.log("Starting chain sample");
const output = [];
output.push(yield context.df.callActivity("E1_SayHello", "Tokyo"));
output.push(yield context.df.callActivity("E1_SayHello", "Seattle"));
output.push(yield context.df.callActivity("E1_SayHello", "London"));
return output;
});
5. オーケストレーター関数を作成
? function.json を以下の JavaScript に置き換えます。
{
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
Orchestration Client
(HttpStart)
Orchestrator
(OrchestratorFunction)
Activity Function
(E1_SayHello)
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": ["get", "post"]
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": ”in"
}
]
}
const df = require("durable-functions");
module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName,
undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req,
instanceId);
};
const df = require("durable-functions");
module.exports = df.orchestrator(function*(context){
context.log("Starting chain sample");
const output = [];
output.push(yield context.df.callActivity("E1_SayHello", "Tokyo"));
output.push(yield context.df.callActivity("E1_SayHello", "Seattle"));
output.push(yield context.df.callActivity("E1_SayHello", "London"));
return output;
});
{
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
index.js
function.json
6. アクティビティ関数を作成
? 前の手順を繰り返し、HTTP Trigger Templateを使用して 2 つ目の関数を作成しま
す。 今回は関数に 「 E1_SayHello 」 と名前を付けます。
? index.js を以下の JavaScript に置き換えます。
module.exports = async function(context) {
return `Hello ${context.bindings.name}!`;
};
6. アクティビティ関数を作成
? function.json を以下の JavaScript に置き換えます。
{
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in"
}
]
}
Orchestration Client
(HttpStart)
Orchestrator
(OrchestratorFunction)
Activity Function
(E1_SayHello)
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": ["get", "post"]
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": ”in"
}
]
}
const df = require("durable-functions");
module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName,
undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req,
instanceId);
};
const df = require("durable-functions");
module.exports = df.orchestrator(function*(context){
context.log("Starting chain sample");
const output = [];
output.push(yield context.df.callActivity("E1_SayHello", "Tokyo"));
output.push(yield context.df.callActivity("E1_SayHello", "Seattle"));
output.push(yield context.df.callActivity("E1_SayHello", "London"));
return output;
});
{
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
module.exports = async function(context) {
return `Hello ${context.bindings.name}!`;
};
{
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in"
}
]
}
index.js
function.json
7. Azure へのサインイン
? [Azure: Functions] 領域で、[Sign in to Azure...](Azure にサインインする...) を選択し
ます。
※Azure アカウントがない場合は無償アカウントを作成して下さい
https://azure.microsoft.com/ja-jp/free/
8. Azure にプロジェクトを発行
? [Azure: Functions] 領域で、[Deploy to Function App](関数アプリにデプロイ) アイコ
ンを選択します。
8. Azure にプロジェクトを発行
? [サブスクリプションを選択] してから、 [+ Create New Function App in Azure](+
Azure で新しい Function App を作成) を選択します。
8. Azure にプロジェクトを発行
? 「顿别辫濒辞测」を选択します。
9. Azure で関数をテスト
? ブラウザでオーケストラーの情報を確認します。
https://<function名>.azurewebsites.net/api/orchestrators/OrchestratorFunction
出力結果例:
{
"id": "a42bfdf91f9a49da9c9558e2ef5c7a65",
"statusQueryGetUri": "https://decode-
horike.azurewebsites.net/runtime/webhooks/durabletask/instances/a42bfdf91f9a49da9c9558e2ef5c7a65?taskHub
=DurableFunctionsHub&connection=Storage&code=BId08/uK/2jAhDKF3bNjgNPzJGdGfcalR3dlm6PJyate/aG/rtHZ
VA==",
"sendEventPostUri": "https://decode-
horike.azurewebsites.net/runtime/webhooks/durabletask/instances/a42bfdf91f9a49da9c9558e2ef5c7a65/raiseEve
nt/{eventName}?taskHub=DurableFunctionsHub&connection=Storage&code=BId08/uK/2jAhDKF3bNjgNPzJGdGfc
alR3dlm6PJyate/aG/rtHZVA==",
????
9. Azure で関数をテスト
? 前ページのstatusQueryGetUri をブラウザのURLにコピペし、オーケストラーの状態を
確認します。
出力結果例:
{
"instanceId": "6fa01dd927a245229cff60e9596d01ee",
"runtimeStatus": "Completed",
"input": null,
"customStatus": null,
"output": [
"Hello Tokyo!",
"Hello Seattle!",
"Hello London!"
],
"createdTime": "2019-05-28T14:10:02Z",
"lastUpdatedTime": "2019-05-28T14:10:02Z"
}
Orchestration Client
(HttpStart)
Orchestrator
(OrchestratorFunction)
Activity Function
(E1_SayHello)
{
"bindings": [
{
"authLevel": "anonymous",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": ["get", "post"]
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": ”in"
}
]
}
const df = require("durable-functions");
module.exports = async function (context, req) {
const client = df.getClient(context);
const instanceId = await client.startNew(req.params.functionName,
undefined, req.body);
context.log(`Started orchestration with ID = '${instanceId}'.`);
return client.createCheckStatusResponse(context.bindingData.req,
instanceId);
};
const df = require("durable-functions");
module.exports = df.orchestrator(function*(context){
context.log("Starting chain sample");
const output = [];
output.push(yield context.df.callActivity("E1_SayHello", "Tokyo"));
output.push(yield context.df.callActivity("E1_SayHello", "Seattle"));
output.push(yield context.df.callActivity("E1_SayHello", "London"));
return output;
});
{
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
module.exports = async function(context) {
return `Hello ${context.bindings.name}!`;
};
{
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in"
}
]
}
index.js
function.json
Appendix
無償アカウントの作成
? https://azure.microsoft.com/ja-jp/free/
チュートリアル
? 今回のタッチアンドトライは公式のチュートリアルをベースにしています。
JavaScript で最初の Durable Functions を作成する
https://docs.microsoft.com/ja-jp/azure/azure-functions/durable/quickstart-js-vscode
Functions Appの前処理
? Durable Functions ExtensionをPortalからInstallします。
? 「Durable Functions HTTP starter」をクリックし「Install」を作成します。
? Installが終わり次第「Cancel」します。
ローカル開発環境
? ローカルでの開発、テストを行うにはセットアップが必要です
Azure Functions V2 を Mac+VSCode で動かすまでの手順
https://qiita.com/miyake/items/83aac5524be91e3811ee
Functionsがサポートするバインディング
Type 1.x 2.x1 トリガー 入力 Output
Blob Storage ? ? ? ? ?
Cosmos DB ? ? ? ? ?
Event Grid ? ? ?
Event Hubs ? ? ? ?
HTTP と Webhooks ? ? ? ?
Microsoft Graph Excel テーブル ? ? ?
Microsoft Graph OneDrive ファイル ? ? ?
Microsoft Graph Outlook メール ? ?
Microsoft Graph Events ? ? ? ?
Microsoft Graph Auth トークン ? ?
Mobile Apps ? ? ?
Notification Hubs ? ?
Queue Storage ? ? ? ?
SendGrid ? ? ?
Service Bus ? ? ? ?
SignalR ? ? ?
Table Storage ? ? ? ?
Timer ? ? ?
Twilio ? ? ?
https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-triggers-bindings#supported-bindings
Ad

Recommended

ソーシャルアプリ勉强会(第一回资料)配布用
ソーシャルアプリ勉强会(第一回资料)配布用
Yatabe Terumasa
?
Selenium webdriver使ってみようず
Selenium webdriver使ってみようず
Oda Shinsuke
?
Develop Web Application with Node.js + Express
Develop Web Application with Node.js + Express
Akinari Tsugo
?
Selenium 触ってみよう
Selenium 触ってみよう
Oda Shinsuke
?
10分で作る Node.js Auto Scale 環境 with CloudFormation
10分で作る Node.js Auto Scale 環境 with CloudFormation
Kazuyuki Honda
?
Backbone.js
Backbone.js
daisuke shimizu
?
Node.js勉強会 Framework Koa
Node.js勉強会 Framework Koa
kamiyam .
?
PHP 2大 web フレームワークの徹底比較!
PHP 2大 web フレームワークの徹底比較!
Shohei Okada
?
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
Kiyoshi Sawada
?
JavaScript/CSS 2015 Autumn
JavaScript/CSS 2015 Autumn
Koji Ishimoto
?
Pro aspnetmvc3framework chap19
Pro aspnetmvc3framework chap19
Hideki Hashizume
?
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
Kiyoshi Sawada
?
Selenium webdriver使ってみようず
Selenium webdriver使ってみようず
Oda Shinsuke
?
アップルのテンプレートは有害と考えられる
アップルのテンプレートは有害と考えられる
Brian Gesiak
?
颈翱厂ビヘイビア駆动开発
颈翱厂ビヘイビア駆动开発
Brian Gesiak
?
自作苍辞诲别.箩蝉フレームワークと苍驳颈苍虫を使ってラジオサイトを作ってみた
自作苍辞诲别.箩蝉フレームワークと苍驳颈苍虫を使ってラジオサイトを作ってみた
Yuki Takei
?
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
Tomohiro Kumagai
?
sbt, past and future / sbt, 傾向と対策
sbt, past and future / sbt, 傾向と対策
scalaconfjp
?
蝉飞辞辞濒别を试してみた
蝉飞辞辞濒别を试してみた
Yukihiro Katsumi
?
厂濒补肠办の滨苍肠辞尘颈苍驳奥别产丑辞辞办蝉と翱耻迟驳辞颈苍驳奥别产丑辞辞办蝉を使って电子工作と连携させてみよう
厂濒补肠办の滨苍肠辞尘颈苍驳奥别产丑辞辞办蝉と翱耻迟驳辞颈苍驳奥别产丑辞辞办蝉を使って电子工作と连携させてみよう
Shigeo Ueda
?
Introduction of aws-cli
Introduction of aws-cli
Masaaki HIROSE
?
贬罢惭尝5&补尘辫;础笔滨総まくり
贬罢惭尝5&补尘辫;础笔滨総まくり
Shumpei Shiraishi
?
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 3.5.0対応)
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 3.5.0対応)
fisuda
?
贰濒补蝉迟颈肠蝉别补谤肠丑の基本动作まとめ
贰濒补蝉迟颈肠蝉别补谤肠丑の基本动作まとめ
朋哉 池田
?
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
y_taka_23
?
サーバーレスの常識を覆す Azure Durable Functionsを使い倒す
サーバーレスの常識を覆す Azure Durable Functionsを使い倒す
Yuta Matsumura
?
[Japan Tech summit 2017] APP 004
[Japan Tech summit 2017] APP 004
Microsoft Tech Summit 2017
?
Azure serverless!! azure functionsでサーバーを意識しない開発
Azure serverless!! azure functionsでサーバーを意識しない開発
Yuki Hattori
?

More Related Content

What's hot (19)

EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
Kiyoshi Sawada
?
JavaScript/CSS 2015 Autumn
JavaScript/CSS 2015 Autumn
Koji Ishimoto
?
Pro aspnetmvc3framework chap19
Pro aspnetmvc3framework chap19
Hideki Hashizume
?
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
Kiyoshi Sawada
?
Selenium webdriver使ってみようず
Selenium webdriver使ってみようず
Oda Shinsuke
?
アップルのテンプレートは有害と考えられる
アップルのテンプレートは有害と考えられる
Brian Gesiak
?
颈翱厂ビヘイビア駆动开発
颈翱厂ビヘイビア駆动开発
Brian Gesiak
?
自作苍辞诲别.箩蝉フレームワークと苍驳颈苍虫を使ってラジオサイトを作ってみた
自作苍辞诲别.箩蝉フレームワークと苍驳颈苍虫を使ってラジオサイトを作ってみた
Yuki Takei
?
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
Tomohiro Kumagai
?
sbt, past and future / sbt, 傾向と対策
sbt, past and future / sbt, 傾向と対策
scalaconfjp
?
蝉飞辞辞濒别を试してみた
蝉飞辞辞濒别を试してみた
Yukihiro Katsumi
?
厂濒补肠办の滨苍肠辞尘颈苍驳奥别产丑辞辞办蝉と翱耻迟驳辞颈苍驳奥别产丑辞辞办蝉を使って电子工作と连携させてみよう
厂濒补肠办の滨苍肠辞尘颈苍驳奥别产丑辞辞办蝉と翱耻迟驳辞颈苍驳奥别产丑辞辞办蝉を使って电子工作と连携させてみよう
Shigeo Ueda
?
Introduction of aws-cli
Introduction of aws-cli
Masaaki HIROSE
?
贬罢惭尝5&补尘辫;础笔滨総まくり
贬罢惭尝5&补尘辫;础笔滨総まくり
Shumpei Shiraishi
?
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 3.5.0対応)
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 3.5.0対応)
fisuda
?
贰濒补蝉迟颈肠蝉别补谤肠丑の基本动作まとめ
贰濒补蝉迟颈肠蝉别补谤肠丑の基本动作まとめ
朋哉 池田
?
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
y_taka_23
?
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
Kiyoshi Sawada
?
JavaScript/CSS 2015 Autumn
JavaScript/CSS 2015 Autumn
Koji Ishimoto
?
Pro aspnetmvc3framework chap19
Pro aspnetmvc3framework chap19
Hideki Hashizume
?
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
EWD 3トレーニングコース#33 ewd-xpressアプリケーションからREST/Webサービスにアクセスする
Kiyoshi Sawada
?
Selenium webdriver使ってみようず
Selenium webdriver使ってみようず
Oda Shinsuke
?
アップルのテンプレートは有害と考えられる
アップルのテンプレートは有害と考えられる
Brian Gesiak
?
颈翱厂ビヘイビア駆动开発
颈翱厂ビヘイビア駆动开発
Brian Gesiak
?
自作苍辞诲别.箩蝉フレームワークと苍驳颈苍虫を使ってラジオサイトを作ってみた
自作苍辞诲别.箩蝉フレームワークと苍驳颈苍虫を使ってラジオサイトを作ってみた
Yuki Takei
?
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
Tomohiro Kumagai
?
sbt, past and future / sbt, 傾向と対策
sbt, past and future / sbt, 傾向と対策
scalaconfjp
?
蝉飞辞辞濒别を试してみた
蝉飞辞辞濒别を试してみた
Yukihiro Katsumi
?
厂濒补肠办の滨苍肠辞尘颈苍驳奥别产丑辞辞办蝉と翱耻迟驳辞颈苍驳奥别产丑辞辞办蝉を使って电子工作と连携させてみよう
厂濒补肠办の滨苍肠辞尘颈苍驳奥别产丑辞辞办蝉と翱耻迟驳辞颈苍驳奥别产丑辞辞办蝉を使って电子工作と连携させてみよう
Shigeo Ueda
?
贬罢惭尝5&补尘辫;础笔滨総まくり
贬罢惭尝5&补尘辫;础笔滨総まくり
Shumpei Shiraishi
?
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 3.5.0対応)
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 3.5.0対応)
fisuda
?
贰濒补蝉迟颈肠蝉别补谤肠丑の基本动作まとめ
贰濒补蝉迟颈肠蝉别补谤肠丑の基本动作まとめ
朋哉 池田
?
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
思ったほど怖くない! Haskell on JVM 超入門 #jjug_ccc #ccc_l8
y_taka_23
?

Similar to Azure で Serverless 初心者向けタッチ&トライ (20)

サーバーレスの常識を覆す Azure Durable Functionsを使い倒す
サーバーレスの常識を覆す Azure Durable Functionsを使い倒す
Yuta Matsumura
?
[Japan Tech summit 2017] APP 004
[Japan Tech summit 2017] APP 004
Microsoft Tech Summit 2017
?
Azure serverless!! azure functionsでサーバーを意識しない開発
Azure serverless!! azure functionsでサーバーを意識しない開発
Yuki Hattori
?
Azure Functions 入門
Azure Functions 入門
jz5 MATSUE
?
20190514 Smart Store - Azure servlerless architecture
20190514 Smart Store - Azure servlerless architecture
Issei Hiraoka
?
Smart Store サーバーレスアーキテクチャ編
Smart Store サーバーレスアーキテクチャ編
Microsoft Azure Japan
?
[Japan Tech summit 2017] APP 003
[Japan Tech summit 2017] APP 003
Microsoft Tech Summit 2017
?
サーバー管理よ、サヨウナラ。サーバーレス アーキテクチャの意義と実践
サーバー管理よ、サヨウナラ。サーバーレス アーキテクチャの意義と実践
真吾 吉田
?
Azure Functionsでサーバーレスアプリケーション構築
Azure Functionsでサーバーレスアプリケーション構築
ryosuke matsumura
?
[AC11] サーバー管理よ、サヨウナラ。サーバーレスアーキテクチャの意義と実践
[AC11] サーバー管理よ、サヨウナラ。サーバーレスアーキテクチャの意義と実践
de:code 2017
?
础锄耻谤别をフル活用したサーバーレスの潮流について
础锄耻谤别をフル活用したサーバーレスの潮流について
真吾 吉田
?
ゆるふわAzure Functions
ゆるふわAzure Functions
Keiji Kamebuchi
?
Azure Functions と Serverless - 概要と企業向け Tips
Azure Functions と Serverless - 概要と企業向け Tips
Keiji Kamebuchi
?
Azure Functionsでサーバーレスアプリケーション構築
Azure Functionsでサーバーレスアプリケーション構築
ryosuke matsumura
?
「Azure durable functions」の概要
「Azure durable functions」の概要
裕之 木下
?
Serverless Architecture Overview #cdevc
Serverless Architecture Overview #cdevc
Masahiro NAKAYAMA
?
て?きる!サーハ?レスアーキテクチャ
て?きる!サーハ?レスアーキテクチャ
azuma satoshi
?
Azure Functions あれこれ
Azure Functions あれこれ
Yasuaki Matsuda
?
20190731 Azure Functions x Line at Azure Tech Lab #4
20190731 Azure Functions x Line at Azure Tech Lab #4
Issei Hiraoka
?
[Oracle Innovation Summit Tokyo 2018] Fn Project: Next Generation Serverless ...
[Oracle Innovation Summit Tokyo 2018] Fn Project: Next Generation Serverless ...
オラクルエンジニア通信
?
サーバーレスの常識を覆す Azure Durable Functionsを使い倒す
サーバーレスの常識を覆す Azure Durable Functionsを使い倒す
Yuta Matsumura
?
Azure serverless!! azure functionsでサーバーを意識しない開発
Azure serverless!! azure functionsでサーバーを意識しない開発
Yuki Hattori
?
Azure Functions 入門
Azure Functions 入門
jz5 MATSUE
?
20190514 Smart Store - Azure servlerless architecture
20190514 Smart Store - Azure servlerless architecture
Issei Hiraoka
?
Smart Store サーバーレスアーキテクチャ編
Smart Store サーバーレスアーキテクチャ編
Microsoft Azure Japan
?
サーバー管理よ、サヨウナラ。サーバーレス アーキテクチャの意義と実践
サーバー管理よ、サヨウナラ。サーバーレス アーキテクチャの意義と実践
真吾 吉田
?
Azure Functionsでサーバーレスアプリケーション構築
Azure Functionsでサーバーレスアプリケーション構築
ryosuke matsumura
?
[AC11] サーバー管理よ、サヨウナラ。サーバーレスアーキテクチャの意義と実践
[AC11] サーバー管理よ、サヨウナラ。サーバーレスアーキテクチャの意義と実践
de:code 2017
?
础锄耻谤别をフル活用したサーバーレスの潮流について
础锄耻谤别をフル活用したサーバーレスの潮流について
真吾 吉田
?
ゆるふわAzure Functions
ゆるふわAzure Functions
Keiji Kamebuchi
?
Azure Functions と Serverless - 概要と企業向け Tips
Azure Functions と Serverless - 概要と企業向け Tips
Keiji Kamebuchi
?
Azure Functionsでサーバーレスアプリケーション構築
Azure Functionsでサーバーレスアプリケーション構築
ryosuke matsumura
?
「Azure durable functions」の概要
「Azure durable functions」の概要
裕之 木下
?
Serverless Architecture Overview #cdevc
Serverless Architecture Overview #cdevc
Masahiro NAKAYAMA
?
て?きる!サーハ?レスアーキテクチャ
て?きる!サーハ?レスアーキテクチャ
azuma satoshi
?
Azure Functions あれこれ
Azure Functions あれこれ
Yasuaki Matsuda
?
20190731 Azure Functions x Line at Azure Tech Lab #4
20190731 Azure Functions x Line at Azure Tech Lab #4
Issei Hiraoka
?
[Oracle Innovation Summit Tokyo 2018] Fn Project: Next Generation Serverless ...
[Oracle Innovation Summit Tokyo 2018] Fn Project: Next Generation Serverless ...
オラクルエンジニア通信
?
Ad

Azure で Serverless 初心者向けタッチ&トライ

  • 5. Durable Functions ? Azure Functions extension ? Enables long-running, stateful serverless operations ? Write complex function orchestrations in a single function ? Built on the open-source Durable Task Framework ? Only pay when your code is running ? Orchestrator replays itself to re-establish state every run
  • 6. Durable Patterns Function chaining Fan-out / fan-in Event aggregation Extended Status Monitoring http Async HTTP APIs Human interaction / timeout
  • 9. 流れ 1. Visual Studio Code にAzure Functions 拡張機能をインストール 2. Azure Functions プロジェクトを作成 3. Durable Functions npm パッケージをインストール 4. starter 関数を作成 5. オーケストレーター関数を作成する 6. アクティビティ関数を作成する 7. Azure へのサインイン 8. Azure にプロジェクトを発行 9. Azure で関数をテスト
  • 10. 1. Azure Functions 拡張機能をインストール ? Visual Studio Code で [拡張機能] を開き、azure functions を検索するか、Visual Studio Code でこのリンクを開きます。 ? [インストール] を選択して、Visual Studio Code に拡張機能をインストールします。
  • 11. ? Visual Studio Code を再起動し、アクティビティ バーの Azure アイコンを選択しま す。 サイド バーに Azure Functions 領域が表示されます。 1. Azure Functions 拡張機能をインストール
  • 12. ? Visual Studio Code で、Azure ロゴを選択して [Azure:Functions] 領域を表示し、[新し いプロジェクトの作成] アイコンを選択します。 ? プロジェクト ワークスペースの場所としてデスクトップの「 demo 」のフォルダを選択 し、[選択] をクリックします。 2. Azure Functions プロジェクトを作成
  • 13. ? 関数アプリ プロジェクトの言語は「JavaScript」を選択します。 ? 「V2」を選択します。 ? 「Skip for now」を選択します。 2. Azure Functions プロジェクトを作成
  • 14. ? 「Open in current window」を選択します。 2. Azure Functions プロジェクトを作成
  • 15. 3. Durable Functions npm パッケージをインストール ? VS Codeでターミナルを開き、ワークスペース用のフォルダ「demo」で「npm install durable-functions」 を実行して、durable-functions npm パッケージをインストール します。 ※npmがインストールされていない場合は、事前にnpmをPCにインストールします
  • 16. 4. starter 関数を作成 ? [Azure:Functions] で [関数の作成] アイコンを選択します。 ? 関数アプリ プロジェクトが含まれたフォルダーを選択し、[HTTP trigger] 関数テンプレート を選択します。 ? 関数名として「HttpStart」と入力して Enter キーを押し、[Anonymous] 認証を選択します。
  • 17. 4. starter 関数を作成 ? index.js を以下の JavaScript に置き換えます。 const df = require("durable-functions"); module.exports = async function (context, req) { const client = df.getClient(context); const instanceId = await client.startNew(req.params.functionName, undefined, req.body); context.log(`Started orchestration with ID = '${instanceId}'.`); return client.createCheckStatusResponse(context.bindingData.req, instanceId); };
  • 18. 4. starter 関数を作成 ? function.json を以下の JavaScript に置き換えます。 { "bindings": [ { "authLevel": "anonymous", "name": "req", "type": "httpTrigger", "direction": "in", "route": "orchestrators/{functionName}", "methods": ["get", "post"] }, { "name": "starter", "type": "orchestrationClient", "direction": "in" } ] }
  • 19. Orchestration Client (HttpStart) Orchestrator (OrchestratorFunction) Activity Function (E1_SayHello) { "bindings": [ { "authLevel": "anonymous", "name": "req", "type": "httpTrigger", "direction": "in", "route": "orchestrators/{functionName}", "methods": ["get", "post"] }, { "name": "starter", "type": "orchestrationClient", "direction": ”in" } ] } const df = require("durable-functions"); module.exports = async function (context, req) { const client = df.getClient(context); const instanceId = await client.startNew(req.params.functionName, undefined, req.body); context.log(`Started orchestration with ID = '${instanceId}'.`); return client.createCheckStatusResponse(context.bindingData.req, instanceId); }; index.js function.json
  • 20. 5. オーケストレーター関数を作成 ? 前の手順を繰り返し、HTTP Trigger Templateを使用して 2 つ目の関数を作成しま す。 今回は関数に 「 OrchestratorFunction」 と名前を付けます。 ? index.js を以下の JavaScript に置き換えます。 const df = require("durable-functions"); module.exports = df.orchestrator(function*(context){ context.log("Starting chain sample"); const output = []; output.push(yield context.df.callActivity("E1_SayHello", "Tokyo")); output.push(yield context.df.callActivity("E1_SayHello", "Seattle")); output.push(yield context.df.callActivity("E1_SayHello", "London")); return output; });
  • 21. 5. オーケストレーター関数を作成 ? function.json を以下の JavaScript に置き換えます。 { "bindings": [ { "name": "context", "type": "orchestrationTrigger", "direction": "in" } ] }
  • 22. Orchestration Client (HttpStart) Orchestrator (OrchestratorFunction) Activity Function (E1_SayHello) { "bindings": [ { "authLevel": "anonymous", "name": "req", "type": "httpTrigger", "direction": "in", "route": "orchestrators/{functionName}", "methods": ["get", "post"] }, { "name": "starter", "type": "orchestrationClient", "direction": ”in" } ] } const df = require("durable-functions"); module.exports = async function (context, req) { const client = df.getClient(context); const instanceId = await client.startNew(req.params.functionName, undefined, req.body); context.log(`Started orchestration with ID = '${instanceId}'.`); return client.createCheckStatusResponse(context.bindingData.req, instanceId); }; const df = require("durable-functions"); module.exports = df.orchestrator(function*(context){ context.log("Starting chain sample"); const output = []; output.push(yield context.df.callActivity("E1_SayHello", "Tokyo")); output.push(yield context.df.callActivity("E1_SayHello", "Seattle")); output.push(yield context.df.callActivity("E1_SayHello", "London")); return output; }); { "bindings": [ { "name": "context", "type": "orchestrationTrigger", "direction": "in" } ] } index.js function.json
  • 23. 6. アクティビティ関数を作成 ? 前の手順を繰り返し、HTTP Trigger Templateを使用して 2 つ目の関数を作成しま す。 今回は関数に 「 E1_SayHello 」 と名前を付けます。 ? index.js を以下の JavaScript に置き換えます。 module.exports = async function(context) { return `Hello ${context.bindings.name}!`; };
  • 24. 6. アクティビティ関数を作成 ? function.json を以下の JavaScript に置き換えます。 { "bindings": [ { "name": "name", "type": "activityTrigger", "direction": "in" } ] }
  • 25. Orchestration Client (HttpStart) Orchestrator (OrchestratorFunction) Activity Function (E1_SayHello) { "bindings": [ { "authLevel": "anonymous", "name": "req", "type": "httpTrigger", "direction": "in", "route": "orchestrators/{functionName}", "methods": ["get", "post"] }, { "name": "starter", "type": "orchestrationClient", "direction": ”in" } ] } const df = require("durable-functions"); module.exports = async function (context, req) { const client = df.getClient(context); const instanceId = await client.startNew(req.params.functionName, undefined, req.body); context.log(`Started orchestration with ID = '${instanceId}'.`); return client.createCheckStatusResponse(context.bindingData.req, instanceId); }; const df = require("durable-functions"); module.exports = df.orchestrator(function*(context){ context.log("Starting chain sample"); const output = []; output.push(yield context.df.callActivity("E1_SayHello", "Tokyo")); output.push(yield context.df.callActivity("E1_SayHello", "Seattle")); output.push(yield context.df.callActivity("E1_SayHello", "London")); return output; }); { "bindings": [ { "name": "context", "type": "orchestrationTrigger", "direction": "in" } ] } module.exports = async function(context) { return `Hello ${context.bindings.name}!`; }; { "bindings": [ { "name": "name", "type": "activityTrigger", "direction": "in" } ] } index.js function.json
  • 26. 7. Azure へのサインイン ? [Azure: Functions] 領域で、[Sign in to Azure...](Azure にサインインする...) を選択し ます。 ※Azure アカウントがない場合は無償アカウントを作成して下さい https://azure.microsoft.com/ja-jp/free/
  • 27. 8. Azure にプロジェクトを発行 ? [Azure: Functions] 領域で、[Deploy to Function App](関数アプリにデプロイ) アイコ ンを選択します。
  • 28. 8. Azure にプロジェクトを発行 ? [サブスクリプションを選択] してから、 [+ Create New Function App in Azure](+ Azure で新しい Function App を作成) を選択します。
  • 29. 8. Azure にプロジェクトを発行 ? 「顿别辫濒辞测」を选択します。
  • 30. 9. Azure で関数をテスト ? ブラウザでオーケストラーの情報を確認します。 https://<function名>.azurewebsites.net/api/orchestrators/OrchestratorFunction 出力結果例: { "id": "a42bfdf91f9a49da9c9558e2ef5c7a65", "statusQueryGetUri": "https://decode- horike.azurewebsites.net/runtime/webhooks/durabletask/instances/a42bfdf91f9a49da9c9558e2ef5c7a65?taskHub =DurableFunctionsHub&connection=Storage&code=BId08/uK/2jAhDKF3bNjgNPzJGdGfcalR3dlm6PJyate/aG/rtHZ VA==", "sendEventPostUri": "https://decode- horike.azurewebsites.net/runtime/webhooks/durabletask/instances/a42bfdf91f9a49da9c9558e2ef5c7a65/raiseEve nt/{eventName}?taskHub=DurableFunctionsHub&connection=Storage&code=BId08/uK/2jAhDKF3bNjgNPzJGdGfc alR3dlm6PJyate/aG/rtHZVA==", ????
  • 31. 9. Azure で関数をテスト ? 前ページのstatusQueryGetUri をブラウザのURLにコピペし、オーケストラーの状態を 確認します。 出力結果例: { "instanceId": "6fa01dd927a245229cff60e9596d01ee", "runtimeStatus": "Completed", "input": null, "customStatus": null, "output": [ "Hello Tokyo!", "Hello Seattle!", "Hello London!" ], "createdTime": "2019-05-28T14:10:02Z", "lastUpdatedTime": "2019-05-28T14:10:02Z" }
  • 32. Orchestration Client (HttpStart) Orchestrator (OrchestratorFunction) Activity Function (E1_SayHello) { "bindings": [ { "authLevel": "anonymous", "name": "req", "type": "httpTrigger", "direction": "in", "route": "orchestrators/{functionName}", "methods": ["get", "post"] }, { "name": "starter", "type": "orchestrationClient", "direction": ”in" } ] } const df = require("durable-functions"); module.exports = async function (context, req) { const client = df.getClient(context); const instanceId = await client.startNew(req.params.functionName, undefined, req.body); context.log(`Started orchestration with ID = '${instanceId}'.`); return client.createCheckStatusResponse(context.bindingData.req, instanceId); }; const df = require("durable-functions"); module.exports = df.orchestrator(function*(context){ context.log("Starting chain sample"); const output = []; output.push(yield context.df.callActivity("E1_SayHello", "Tokyo")); output.push(yield context.df.callActivity("E1_SayHello", "Seattle")); output.push(yield context.df.callActivity("E1_SayHello", "London")); return output; }); { "bindings": [ { "name": "context", "type": "orchestrationTrigger", "direction": "in" } ] } module.exports = async function(context) { return `Hello ${context.bindings.name}!`; }; { "bindings": [ { "name": "name", "type": "activityTrigger", "direction": "in" } ] } index.js function.json
  • 35. チュートリアル ? 今回のタッチアンドトライは公式のチュートリアルをベースにしています。 JavaScript で最初の Durable Functions を作成する https://docs.microsoft.com/ja-jp/azure/azure-functions/durable/quickstart-js-vscode
  • 36. Functions Appの前処理 ? Durable Functions ExtensionをPortalからInstallします。 ? 「Durable Functions HTTP starter」をクリックし「Install」を作成します。 ? Installが終わり次第「Cancel」します。
  • 37. ローカル開発環境 ? ローカルでの開発、テストを行うにはセットアップが必要です Azure Functions V2 を Mac+VSCode で動かすまでの手順 https://qiita.com/miyake/items/83aac5524be91e3811ee
  • 38. Functionsがサポートするバインディング Type 1.x 2.x1 トリガー 入力 Output Blob Storage ? ? ? ? ? Cosmos DB ? ? ? ? ? Event Grid ? ? ? Event Hubs ? ? ? ? HTTP と Webhooks ? ? ? ? Microsoft Graph Excel テーブル ? ? ? Microsoft Graph OneDrive ファイル ? ? ? Microsoft Graph Outlook メール ? ? Microsoft Graph Events ? ? ? ? Microsoft Graph Auth トークン ? ? Mobile Apps ? ? ? Notification Hubs ? ? Queue Storage ? ? ? ? SendGrid ? ? ? Service Bus ? ? ? ? SignalR ? ? ? Table Storage ? ? ? ? Timer ? ? ? Twilio ? ? ? https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-triggers-bindings#supported-bindings