狠狠撸

狠狠撸Share a Scribd company logo
Azure Functions
DINO WANG
Dino Wang
禾盛數碼科技 hexdigits
twMVC 共同創辦人
現任 Microsoft Azure MVP
合著「ASP.NET MVC 5 網站開發美學」繁簡體版
曾任微軟 TechDay & MSDN 講師
https://www.facebook.com/dinowang
dino@hexdigits.com
2
Agenda
Azure Functions 概觀
暸解 Azure Functions 應用程式結構
開發人員基礎知識
應用場景 demo
3
什麼是 Azure Functions
Azure 中具有 計算能力 的一種服務類型
基於 雲端事件驅動 並且 易於開發 的設計
提供 使用才付費的 (pay-per-use) 計費方式
免於管理伺服器的 Serverless 架構
4
快速演進
目前為 Preview 0.4 版
5 月發佈,7 月升 0.3 版,8 月升 0.4 版,都是 runtime 改版,向前兼容
https://github.com/Azure/azure-webjobs-sdk-script/releases
活躍的討論區
StackOverflow
http://stackoverflow.com/questions/tagged/azure-functions
MSDN Forum
https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=AzureFunctions
5
常見應用場景
排程工作
使用 Azure 服務所引發的各種事件處理
其他 SaaS 服務的事件處理,例如 OneDrive
Single Page App 的快速建置
行動應用的後端系統
IoT 的即時流處理
Bot 應用
6
認識計價方式
執行時間 以及 執行次數。
每月 一百萬次 或 總執行時數於 400,000 GB-s 內免費。
https://azure.microsoft.com/en-us/pricing/details/functions/
在 Preview 期間不提供 SLA。
或在專屬的 App Service 中執行。
7
Gibabyte Seconds
Serverless 架構
"Serverless" 沒有伺服器也太神了吧?
? 不,你的 code 當然都是在機器上執行的。
意味一個不需要你花心思進行資源調度的執行環境。
? 只要上傳你的程式碼 (Bring your own code) 。
? 不需要考慮執行時期如何調整規模,煩惱全交給 Serverless 架構。
8
應優先掌握的開發重點
? Triggers
? 事件驅動的來源
? 來源事件訊息
? 所有的 Function 必有
一個 Trigger 事件作為
起始
9
? Binding
? 綁定資源,包含事件訊息
? 包含輸入、輸出的資源
? 利用預先設定綁定的雲端
資源,簡化開發專注流程
Azure Functions Bindings
類型 相關服務 Trigge
r
Input Outpu
t
Schedule Azure Functions ?
HTTP Rest/WebHook Azure Functions ? ?
Blob Azure Storage ? ? ?
Queue Azure Storage ? ?
Table Azure Storage ? ?
NoSQL Azure DocumentDB ? ?
Streams Azure EventHub ? ?
Push Notifications ?
10
Azure Functions 特性
整合
可輕易與 Azure 多項服務進行整合 (事件源)
多種佈署方式
整合 GitHub、VSTS、Git、BitBucket、OneDrive、Dropbox、… 為部署來源
可選的授權服務提供者
Azure AD、Facebook、Google、Twitter、Microsoft Account (OAuth
providers)
11
Azure Functions 特性
可使用多種開發語言
C#、Node、Python、F#、PHP、Batch、Bash
可依需求安裝元件
NuGet、NPM
12
名稱
13
名稱 說明
Azure Functions Azure 提供的一項服務
Function App
運用 Azure Functions
所開發的應用程式實例
建立 Function App
https://functions.azure.com
14
建立 Function App
http://portal.azure.com
App Service Plan 的選擇
傳統 Classic
採用專責 App Service VM 執行 Function App。
動態 Dynamic
由 Azure 自動分配指定執行 Function App 的實例,盡可能地利用
Azure 的資源,並且以 pay-per-use 的方式計算費用。
16
Function App 控制台
17
demo
第一個 FUNCTION APP 「HELLO WORLD」
18
關於 TimerTrigger
使用 CRON 表示式
注意 CRON 表示式由 6 個欄位組成:
{second} {minute} {hour} {day} {month} {day of the week}
支援的標記符號有 * , - /
Azure Functions 與 WebJob 同樣都支持秒級的 CRON 表示式
19
http://goo.gl/Fqn58F
關於 TimerTrigger
不熟悉 CRON 的朋友可使用一些線上服務產生表示式
? http://www.cronmaker.com/
? http://crontab.guru/
? http://crontab-generator.org/
但以上都只提供 5 個欄位的 CRON 表示式,沒有到秒級
20
在 Hello World 裡學習到
建立第一個 Function App 以及設定的界面
Trigger、Binding 在 Function 中的角色
以 C# 為例的程式本體 run.csx (C# Script)
21
進一步地探索 Function App
Function App 是基於 Azure App Services 的架構
所以你可以使用 Kudu 服務來更好的暸解 Function App
? 部署結構
? API Keys
? 執行紀錄
22
demo
使用 KUDU 探索 FUNCTION APP 的結構
23
關於 API Keys
由 App Service 中取得 API Key
D:homedataFunctionssecretshost.json
全域 API Key 能驅動 Function app 中所有 function
但不包含 disabled function
24
關於 API Keys
自訂 API Key 可以為個別的 function 定義額外的 API Key
做法是在 secret (D:homedataFunctionssecrets) 目錄下新增與
function 同名的 JSON 檔案。
D:homedataFunctionssecrets{FuncName}.json
25
在 Hello World 裡學習到
人工建立第一個 Function 以及設定的界面
Trigger、Binding 在 Function 中的角色
Function 程式本體 (以 C# Scripts 為例)
Function 的部署結構、function.json 以及 API Keys 的維護方式
26
在自己的編輯器裡寫
Function App
Code 總是需要管理,在 Function App Console 上寫 code 不是常
態,我們需要先開發、測試、部署,並且可以妥善版本控管的機制。
只是剛開始寫時 function.json 真的是個很卡的東西 …
27
參考官方的 templates
28
利用 Yeoman generator
generator-azurefunctions 是你的好朋友
29
什麼?壞了!
30
.NET Developer
了解 C# Script (.csx) 的開發要領
如何由 Azure Portal 進行開發
如同開發 HelloWorld 範例一樣使用線上編輯器
如何由 Source Control (如 GitHub) 進行開發
由版本控制部署的 Function 無法在 Portal 進行修改 (一般情況)
31
Azure Functions C# developer reference
https://azure.microsoft.com/en-us/documentation/articles/functions-reference-csharp/
Function App from CI
建立 GitHub repository (可用 private)
本地端產生專案目錄,例如 demo,並建立本地 repo.
使用 yeoman 產生一個 Function
完成 Function 所需的程式碼
Commit 以及 push 到 GitHub repo.
設定 Function App 自動由 GitHub 部署
32
demo
由 CI 部署 FUNCTION APP
33
VSCode / Intellisense
如果你的 VSCode 無法順利提供 Intellisense,試著在編輯期間暫時
將副檔名 Run.csx 更名為 Run.cs 即可。
若您使用 ATOM 編輯器亦相同,問題源自於提供語法解析
OmniSharp 套件,記得安裝。
送上版控前請確保 Run 副檔名為 .csx。
34
Function App Structures
獨立 Function 目錄
有 function.json
有 run.csx
可以存在非 Function 的目錄
沒有 function.json 的目錄
存放共用類別或其他資源檔案
如右圖中的 Slack 存放 C# Script 共用程式碼
35
demo
以 FUNCTION APP 進行縮圖處理
36
在 MakeThumb 裡學習到
Storage Binding 以及 Binding 參數的設置
C# Script 使用多種 GAC 組件/和外部組件所需要的代碼
Function 載入第三方元件的做法 (project.json)
37
C# Script
#r "AssemblyName"
自 GAC 增加參考的組件
#load "AnotherScript"
載入其他的 C# Script 檔案
第三方的套件透過 project.json 定義,讓 Azure Functions 自動下載
C# Script 內不能含有 Namespace
38
注意句尾
不必加上 ";"
接下來 …
39
凡事都有個 Bot
40
Slack Bot偽
合適的使用情境
Bot 經常不是全時服務
以使用次數、執行時間計算的 Azure Functions 很搭
41
整合 Slack 的多種方式
Outgoing Webhooks
Incoming Webhooks
Slash Commands
Bot Users
42
Slack Command + Functions
43
Slack Client
Azure Functions
( HttpTrigger )
Slash Command + Functions
Slash Command 的形式
/{命令名稱} {命令參數}
Slash Command 送出參數至定義的 Function URL (HTTP Post)
回應 Slash Command
44
Azure Functions URL
一個 HttpTrigger 對外公開的 URL 結構
另外應加上 API Key
45
demo
SLACK 整合 FUNCTION APP
46
週四固定聚會
Sample code https://github.com/dinowang/comopencamp-af
Any question?
dino@hexdigits.com | https://mvc.tw/coding4fun
週四的 7:30 PM 到 9:00 PM twMVC 有固定聚會
相約在伯朗咖啡科大店
國定假日、放颱風假不要來
47
Thanks
48

More Related Content

What's hot (19)

02 azure devops pipeline - build
02 azure devops pipeline - build02 azure devops pipeline - build
02 azure devops pipeline - build
Alan Tsai
?
Bluemix API Services Comparison
Bluemix API Services Comparison Bluemix API Services Comparison
Bluemix API Services Comparison
Chang-Yen Huang
?
Workflow engine
Workflow engineWorkflow engine
Workflow engine
Pokai Hsu
?
GDG Taichung - Firebase Introduction 01
GDG Taichung - Firebase Introduction 01GDG Taichung - Firebase Introduction 01
GDG Taichung - Firebase Introduction 01
Duran Hsieh
?
Internet Cloud Operations - ChinaNetcloud & AWS Event Beijing
Internet Cloud Operations - ChinaNetcloud & AWS Event BeijingInternet Cloud Operations - ChinaNetcloud & AWS Event Beijing
Internet Cloud Operations - ChinaNetcloud & AWS Event Beijing
ChinaNetCloud
?
GDG Taichung: Cloud Study Jam ML API
GDG Taichung: Cloud Study Jam ML APIGDG Taichung: Cloud Study Jam ML API
GDG Taichung: Cloud Study Jam ML API
Duran Hsieh
?
Swagger
SwaggerSwagger
Swagger
Yan-ren Tsai
?
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 TaiwanAzure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Will Huang
?
Bluemix Api Connect
Bluemix Api ConnectBluemix Api Connect
Bluemix Api Connect
Chang-Yen Huang
?
淺談系統監控與 AWS CloudWatch 的應用
淺談系統監控與 AWS CloudWatch 的應用淺談系統監控與 AWS CloudWatch 的應用
淺談系統監控與 AWS CloudWatch 的應用
Rick Hwang
?
03 azure devops pipeline - release
03 azure devops pipeline - release03 azure devops pipeline - release
03 azure devops pipeline - release
Alan Tsai
?
MVC MVVM MVVMC
MVC MVVM MVVMCMVC MVVM MVVMC
MVC MVVM MVVMC
Ng Hui Qin
?
使用 Sierra API, DNA 初探
使用 Sierra API, DNA 初探使用 Sierra API, DNA 初探
使用 Sierra API, DNA 初探
twtw
?
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
Shengyou Fan
?
2016 Azurebootcamp 中國Azure 使用經驗
2016 Azurebootcamp 中國Azure 使用經驗2016 Azurebootcamp 中國Azure 使用經驗
2016 Azurebootcamp 中國Azure 使用經驗
Edward Kuo
?
不談 IAM
不談 IAM不談 IAM
不談 IAM
Cliff Chao-kuan Lu
?
美团点评技术沙龙011 - 客户端用户体验数据量化
美团点评技术沙龙011 - 客户端用户体验数据量化美团点评技术沙龙011 - 客户端用户体验数据量化
美团点评技术沙龙011 - 客户端用户体验数据量化
美团点评技术团队
?
ASP.NET MVC The Begining
ASP.NET MVC The BeginingASP.NET MVC The Begining
ASP.NET MVC The Begining
Simon Huang
?
關於 Javascript 非同步的那些事兒 公開版
關於 Javascript 非同步的那些事兒 公開版關於 Javascript 非同步的那些事兒 公開版
關於 Javascript 非同步的那些事兒 公開版
Kirk Chen
?
02 azure devops pipeline - build
02 azure devops pipeline - build02 azure devops pipeline - build
02 azure devops pipeline - build
Alan Tsai
?
Bluemix API Services Comparison
Bluemix API Services Comparison Bluemix API Services Comparison
Bluemix API Services Comparison
Chang-Yen Huang
?
Workflow engine
Workflow engineWorkflow engine
Workflow engine
Pokai Hsu
?
GDG Taichung - Firebase Introduction 01
GDG Taichung - Firebase Introduction 01GDG Taichung - Firebase Introduction 01
GDG Taichung - Firebase Introduction 01
Duran Hsieh
?
Internet Cloud Operations - ChinaNetcloud & AWS Event Beijing
Internet Cloud Operations - ChinaNetcloud & AWS Event BeijingInternet Cloud Operations - ChinaNetcloud & AWS Event Beijing
Internet Cloud Operations - ChinaNetcloud & AWS Event Beijing
ChinaNetCloud
?
GDG Taichung: Cloud Study Jam ML API
GDG Taichung: Cloud Study Jam ML APIGDG Taichung: Cloud Study Jam ML API
GDG Taichung: Cloud Study Jam ML API
Duran Hsieh
?
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 TaiwanAzure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Azure Web App on Linux @ Global Azure Bootcamp 2017 Taiwan
Will Huang
?
淺談系統監控與 AWS CloudWatch 的應用
淺談系統監控與 AWS CloudWatch 的應用淺談系統監控與 AWS CloudWatch 的應用
淺談系統監控與 AWS CloudWatch 的應用
Rick Hwang
?
03 azure devops pipeline - release
03 azure devops pipeline - release03 azure devops pipeline - release
03 azure devops pipeline - release
Alan Tsai
?
使用 Sierra API, DNA 初探
使用 Sierra API, DNA 初探使用 Sierra API, DNA 初探
使用 Sierra API, DNA 初探
twtw
?
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
Shengyou Fan
?
2016 Azurebootcamp 中國Azure 使用經驗
2016 Azurebootcamp 中國Azure 使用經驗2016 Azurebootcamp 中國Azure 使用經驗
2016 Azurebootcamp 中國Azure 使用經驗
Edward Kuo
?
美团点评技术沙龙011 - 客户端用户体验数据量化
美团点评技术沙龙011 - 客户端用户体验数据量化美团点评技术沙龙011 - 客户端用户体验数据量化
美团点评技术沙龙011 - 客户端用户体验数据量化
美团点评技术团队
?
ASP.NET MVC The Begining
ASP.NET MVC The BeginingASP.NET MVC The Begining
ASP.NET MVC The Begining
Simon Huang
?
關於 Javascript 非同步的那些事兒 公開版
關於 Javascript 非同步的那些事兒 公開版關於 Javascript 非同步的那些事兒 公開版
關於 Javascript 非同步的那些事兒 公開版
Kirk Chen
?

Viewers also liked (20)

Introduction to Azure Functions
Introduction to Azure FunctionsIntroduction to Azure Functions
Introduction to Azure Functions
Marco Parenzan
?
Serverles com Azure Functions & DocumentDB
Serverles com Azure Functions & DocumentDBServerles com Azure Functions & DocumentDB
Serverles com Azure Functions & DocumentDB
José Roberto Araújo
?
Introduction to Azure Functions - Tutorial
Introduction to Azure Functions - TutorialIntroduction to Azure Functions - Tutorial
Introduction to Azure Functions - Tutorial
BizTalk360
?
Azure Functions Real World Examples
Azure Functions Real World Examples Azure Functions Real World Examples
Azure Functions Real World Examples
Yochay Kiriaty
?
Serverless with Azure Functions
Serverless with Azure FunctionsServerless with Azure Functions
Serverless with Azure Functions
Andreas Willich
?
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
DynamicInfraDays
?
Using Azure Functions for Integration
Using Azure Functions for IntegrationUsing Azure Functions for Integration
Using Azure Functions for Integration
BizTalk360
?
Azure - The Good Parts
Azure - The Good PartsAzure - The Good Parts
Azure - The Good Parts
Mark Allan
?
Azure functionsAzure functions
Azure functions
Eduard Tomàs
?
An introduction to Atlassian Bitbucket Pipelines
An introduction to Atlassian Bitbucket PipelinesAn introduction to Atlassian Bitbucket Pipelines
An introduction to Atlassian Bitbucket Pipelines
Dave Clark
?
Chris Anderson and Yochay Kiriaty - Serverless Patterns with Azure Functions
Chris Anderson and Yochay Kiriaty - Serverless Patterns with Azure FunctionsChris Anderson and Yochay Kiriaty - Serverless Patterns with Azure Functions
Chris Anderson and Yochay Kiriaty - Serverless Patterns with Azure Functions
ServerlessConf
?
Serverless Architecture - Azure Logic apps
Serverless Architecture - Azure Logic appsServerless Architecture - Azure Logic apps
Serverless Architecture - Azure Logic apps
Puneet Ghanshani
?
Google Cloud Platform
Google Cloud Platform Google Cloud Platform
Google Cloud Platform
Francesco Marchitelli
?
OpenWhisk - Serverless Architecture
OpenWhisk - Serverless Architecture OpenWhisk - Serverless Architecture
OpenWhisk - Serverless Architecture
Dev_Events
?
Adapt or Die: Serverless Microservices
Adapt or Die: Serverless MicroservicesAdapt or Die: Serverless Microservices
Adapt or Die: Serverless Microservices
Apigee | Google Cloud
?
Serverless - When to FaaS?
Serverless - When to FaaS?Serverless - When to FaaS?
Serverless - When to FaaS?
Benny Bauer
?
Serverless Azure
Serverless AzureServerless Azure
Serverless Azure
Mark Allan
?
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Mitoc Group
?
狠狠撸 Wars- The Force Sleeps
狠狠撸 Wars- The Force Sleeps狠狠撸 Wars- The Force Sleeps
狠狠撸 Wars- The Force Sleeps
Empowered Presentations
?
Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.
Emiland
?
Introduction to Azure Functions
Introduction to Azure FunctionsIntroduction to Azure Functions
Introduction to Azure Functions
Marco Parenzan
?
Serverles com Azure Functions & DocumentDB
Serverles com Azure Functions & DocumentDBServerles com Azure Functions & DocumentDB
Serverles com Azure Functions & DocumentDB
José Roberto Araújo
?
Introduction to Azure Functions - Tutorial
Introduction to Azure Functions - TutorialIntroduction to Azure Functions - Tutorial
Introduction to Azure Functions - Tutorial
BizTalk360
?
Azure Functions Real World Examples
Azure Functions Real World Examples Azure Functions Real World Examples
Azure Functions Real World Examples
Yochay Kiriaty
?
Serverless with Azure Functions
Serverless with Azure FunctionsServerless with Azure Functions
Serverless with Azure Functions
Andreas Willich
?
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
ContainerDays NYC 2016: "OpenWhisk: A Serverless Computing Platform" (Rodric ...
DynamicInfraDays
?
Using Azure Functions for Integration
Using Azure Functions for IntegrationUsing Azure Functions for Integration
Using Azure Functions for Integration
BizTalk360
?
Azure - The Good Parts
Azure - The Good PartsAzure - The Good Parts
Azure - The Good Parts
Mark Allan
?
Azure functionsAzure functions
Azure functions
Eduard Tomàs
?
An introduction to Atlassian Bitbucket Pipelines
An introduction to Atlassian Bitbucket PipelinesAn introduction to Atlassian Bitbucket Pipelines
An introduction to Atlassian Bitbucket Pipelines
Dave Clark
?
Chris Anderson and Yochay Kiriaty - Serverless Patterns with Azure Functions
Chris Anderson and Yochay Kiriaty - Serverless Patterns with Azure FunctionsChris Anderson and Yochay Kiriaty - Serverless Patterns with Azure Functions
Chris Anderson and Yochay Kiriaty - Serverless Patterns with Azure Functions
ServerlessConf
?
Serverless Architecture - Azure Logic apps
Serverless Architecture - Azure Logic appsServerless Architecture - Azure Logic apps
Serverless Architecture - Azure Logic apps
Puneet Ghanshani
?
OpenWhisk - Serverless Architecture
OpenWhisk - Serverless Architecture OpenWhisk - Serverless Architecture
OpenWhisk - Serverless Architecture
Dev_Events
?
Serverless - When to FaaS?
Serverless - When to FaaS?Serverless - When to FaaS?
Serverless - When to FaaS?
Benny Bauer
?
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Serverless Microservices - Real life story of a Web App that uses AngularJS, ...
Mitoc Group
?
Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.Dear NSA, let me take care of your slides.
Dear NSA, let me take care of your slides.
Emiland
?

Azure Functions