# AZ-204 Developing Solutions for Microsoft Azure ###### tags: `Azure` `Azure Developing` `AZ-204` Microsoft Azure開發解決方案(AZ204) 2022/8/15 曹祖聖 簡報檔(講師同意允許可以在所有用途使用簡報檔內容) https://teacher.syset.com LEARNING PATH AZ-204: Create Azure App Service web apps AZ-204: Implement Azure Functions AZ-204: Develop solutions that use Blob storage AZ-204: Develop solutions that use Azure Cosmos DB AZ-204: Implement infrastructure as a service solutions AZ-204: Implement user authentication and authorization AZ-204: Implement secure cloud solutions AZ-204: Implement API Management AZ-204: Develop event-based solutions AZ-204: Develop message-based solutions AZ-204: Instrument solutions to support monitoring and logging AZ-204: Integrate caching and content delivery within solutions https://microsoftlearning.github.io/AZ-204-DevelopingSolutionsforMicrosoftAzure/ 開發 Azure App Service (Web App, Azure Storage) 0. 在Azure Portal建立Azure App Service, Azure Storage Account and container 1. 在本地使用VS Code開發 Asp.net MVC api site for access file on Azure Storage 2. deploy to Azure App Service(web app) 可以在VS code terminal執行 az login -- query webapp list az webapp list --resource-group ManagedPlatform --query "[?starts_with(name, 'imgapi')]" -- query webapp list where name startwith az webapp list --resource-group ManagedPlatform --query "[?starts_with(name, 'imgapi')].{Name:name}" --output tsv -- deploy az webapp deployment source config-zip --resource-group ManagedPlatform --src api.zip --name <name-of-your-api-app> Note: Replace the <name-of-your-api-app> placeholder with the name of the web app that you created previously in this lab. You recently queried this app’s name in the previous steps. 3. 在本地使用VS Code開發 Asp.net MVC web site 4. deploy to Azure App Service(Web App) az login az webapp list --resource-group ManagedPlatform az webapp list --resource-group ManagedPlatform --query "[?starts_with(name, 'imgweb')]" az webapp list --resource-group ManagedPlatform --query "[?starts_with(name, 'imgweb')].{Name:name}" --output tsv az webapp deployment source config-zip --resource-group ManagedPlatform --src web.zip --name <name-of-your-web-app> 開發 Azure Fuction 0. 在Azure Portal建立Azure Function resource 1. 開發機須安裝Azure Functions Core Tools https://docs.microsoft.com/zh-tw/azure/azure-functions/functions-run-local?tabs=v4%2Cwindows%2Ccsharp%2Cportal%2Cbash 2. 使用 Azure Functions Core Tools command建立local Azure Function project 可以在VS code terminal執行 func init --worker-runtime dotnet --force 可以用VS Code開一個Terminal,建立前先cd切換到一個該專案的空目錄 3. 建置一下確認沒有錯誤 可以在VS code terminal執行 dotnet build 4. 在此Azure Fuction裡面建立一個名稱為Echo的 HTTP Trigger,會產生一個echo.cs檔 可以在VS code terminal執行 func new --template "HTTP trigger" --name "Echo" 5. 在echo.cs檔案寫需要處理資料的邏輯 6. 在本地執行Azure Function來進行測試 可以在VS code terminal執行 func start --build 7. 本地測試 可以執行開瀏覽器到此網址測試 http://localhost:7071/api/echo 或使用httprepl工具來測試 可以在VS code terminal執行 dotnet tool install -g Microsoft.dotnet-httprepl httprepl http://localhost:7071 8. Deploy a local function project to an Azure Functions app 可以在VS code terminal執行 (1)登入azure az login (2)將本地Azure Fuction發行到Azure func azure functionapp publish <function-app-name> 開發 App to access Azure Storage 0. 在Azure Portal建立Azure Storage account and container... 1. 開發.net (1)to access Azure Storage for return file list on Azure Storage (2)to create container (3)to upload file 2. 本地測試 dotnet run 開發 App to access Azure Cosmos DB https://docs.microsoft.com/en-us/azure/cosmos-db/consistency-levels Azure Cosmos DB offers five well-defined levels. From strongest to weakest, the levels are: * Strong * Bounded staleness * Session * Consistent prefix * Eventual ![](https://i.imgur.com/VW6ZmOC.png) Load Balancer Layer 4 regional(建立時需要指定region),適用 主機都在同一個機房或同一個region Application Gateway Layer 7 regional(建立時需要指定region) Front Door Layer 7 global(建立時不需要指定region) Traffic Manager DNS global API Management Layer 7 regional 架構上可以混搭,但通常global不會一起用,因為不需要 例如: Traffic Manager -> hosts Traffic Manager ->Application Gateway > hosts Traffic Manager ->Application Gateway >Load Balancer> hosts Lay 4只能看懂 TCP, Port number導向 Lay 7可以導向 http網址位置,可以導向 https://aa.aaa.aaa/a 導向後端不同主機 Front Door會自動檢查後端主機是否活著與反應時間,會導向效能好的主機 Traffic Manager也會檢查後端主機RTT Container 虛擬機VM是硬體虛擬化,每個VM的硬體都是虛擬的 容器是OS作業系統虛擬化,每個容器的OS是虛擬的 * User 人 * Group * Service Principal for單一程式使用的帳號 * Service Principal (for RBAC) 使用command建立,az ad sp create-for-rbac -n YourAppName * app registration (Azure Portal>Azure ADd\可以建立,並新增一個Cred,就會產生一組密碼) * Managed Identity (MI 受控識別) 平台產生的帳號無密碼,例如Azure特定的resource產生的一組帳號 * system assigned (通常在Portal該資源的會有一個Identity屬性,例如Azure Fuction\Identity >System assigned,就可以啟用) ,資源刪除此帳號就會消失 * user assigned (Portal搜尋user assign,User Assigned Manage Identity資源,就可以建立,然後去特定resource,例如 Azure Fuction\Identity > User assigned,選擇剛剛建立的user assigned帳號) 如果有多個resource想要共用一組Managed Identity,就可以考慮使用user assigned 因為如果用system assigned,需要針對每一個azure resource都啟用system assigned,會有多個Managed Identity帳號,指派權限時,就需要設定多組 ### Event Hub Event Hub收事件也可以收串流資料,會自動切partition來讓延遲低反應快 Event Hub就是一個緩衝區 (Azure Hub上的事件通常可以保留1~7天) 為了來不急處理的事件 無法過濾事件,收事件的程式只能收到所有事件 實作上是建立一個namespace,然後才能建Event Hub Consumer Group(類似指標的內容),同一個CG的consumer收到資料的順序是一致的 Event Hub Capture: 可以讓Hub的事件資料自動寫道Azure Storage ### IoT Hub IoT Hub也是類似 Event Hub 只是Event Hub無法知道是誰,所以無法反向送回,但是IoT Hub則可以,因為IoT Hub會註冊Device,所以還可以將一些資訊或命令送回Device) ### Event Grid 有事件派送能力的是Grid 有事件過濾能力,依據事件的不同,有不同的處理方式-> sub訂閱 如果事件consumer還是來不急處理Event Grid,可以從Grid再丟到Event Hub Event Source就是產生Event的來源 Topic是一個訂閱的對象,有一個URL Event Hub/Iot Hub也可以送訊息到Event Grid,再透過Event Grid派送到不童的consumer service bus, event hub 差別 Service bus: message (通常是程式在處理的資料傳給另一個城市) 保證順序 FIFO 保證訊息 一定要能收得到,hub沒有這種特性 Event hub: Event (突然很大量的資料近來,要收集處理) Service Bus 可以有多個接收端呼叫的 consumer 可以被動接收,不需要主動從queue檢查取資料 (較慢,但為了通用) 效能 可以跑很多城市同時處理(取queue資料)也沒有問會將資料序列化成binary來傳輸資料,題,順序也沒有問題 呼叫的 protoco HTTP (雖然較慢,但為了通用) AMQP SBMP (會將資料序列化成binary來傳輸資料,效能最好,但只支援.net Framework) Azure Storage Queue SLA比service bus高