#DOH19
2
Automazione serverless con Azure
Function e PowerShell
Marco Obinu
@OmegaMadLab
#DOH19 3
Organizer & sponsors
GetLatestVersion.it
#DOH19
• Advisory Engineer @ Softjam S.p.A.
• Geek fino al midollo 
@OmegaMadLab
marco.obinu@omegamadlab.com
http://www.omegamadlab.com
https://github.com/OmegaMadLab
https://www.linkedin.com/in/marco-obinu-omegamadlab/
https://www.youtube.com/channel/UCpkBeQSscC1iBvpNP4VNTKQ
4
Marco Obinu
#DOH19 6
Azure Functions e PowerShell: perché?
• Piattoforma serverless event-driven
• Complementare ad Azure Automation
Completa astrazione
dal layer hardware
Scabilità guidata
dagli eventi
Paghi per l’effettivo
utilizzo
#DOH19 7
Trigger e bindings
Triggers Bindings
Blob Binding Direction Binding Direction
Queue Blob Input and Output Graph Onedrive Input and Output
HTTP Queue Output Graph Email Output
Cosmos DB Table Input and Output Graph Event Input and Output
Event Grid CosmoDb Input and Output Notification Hubs Output
Event Hub Event Hubs Output SendGrid Output
MS Graph Event Http Output Service bus Output
Service Bus Graph Excel Input and Output SignalR Input and Output
Timer
https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings
Trigger
Input binding Output binding
8
Anatomia di una PowerShell function
#DOH19 9
Piani di servizio
Resource Consumption plan Premium plan (preview) App Service plan
Scale out Event driven Event driven Manual/autoscale
Max instances 200 20 10-20
Cold start ✅Yes ❌No ❌No
Default time out duration (min) 5 30 30
Max time out duration (min) 10 unbounded unbounded
ACU per instance 100 210-840 100-840
Max memory (GB per instance) 1.5 3.5-14 1.75-14
Function apps per plan 100 100 unbounded
App Service plans 100 per region 100 per resource group 100 per resource group
Storage 1 GB 250 GB 50-1000 GB
Vnet integration ❌No ✅Yes ✅Yes
https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale
#DOH19 10
Struttura del filesystem
PSFunctionApp
MyFirstFunction
run.ps1
function.json
MySecondFunction
run.ps1
function.json
Modules
myFirstHelperModule
myFirstHelperModule.psd1
myFirstHelperModule.psm1
mySecondHelperModule
mySecondHelperModule.psd1
mySecondHelperModule.psm1
local.settings.json
host.json
requirements.psd1
profile.ps1
11
Invio report con Az.ResourceGraph e
SendGrid
12
Interrogazione AzSQLDB con sqlserver
HTTP req HTTP resp
13
Integrazione con Event Grid
14
Alert response con Azure Monitor
#DOH19 15
Integrazione con la rete
Consumption plan
Premium plan
(preview) App Service plan
App Service
Environment
Inbound IP restrictions &
private site access
✅Yes ✅Yes ✅Yes ✅Yes
Virtual network
integration
❌No ✅Yes
(Regional)
✅Yes
(Regional and Gateway)
✅Yes
Virtual network triggers
(non-HTTP)
❌No ❌No ✅Yes ✅Yes
Hybrid Connections ❌No ✅Yes ✅Yes ✅Yes
Outbound IP Restrictions ❌No ❌No ❌No ✅Yes
https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
#DOH19
• Regional vnet integration
16
Integrazione con la rete
https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
#DOH19
• GW vnet integration
17
Integrazione con la rete
https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
#DOH19 18
Integrazione con la rete
https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
• ASE
#DOH19
• Hybrid connection
19
Integrazione con la rete
https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
20
Integrazione con la vnet
HTTP req HTTP resp
#DOH19 21
Sicurezza
• Networking
• IP restrictions e service endpoint
• ASE
• Verso l’esterno
• Managed Service Identity
• Sull’invocazione
• Function e master key
• Integrazione con authentication providers
• Gestione dei dati sensibili
• App Settings
• Integrazione con Key Vault
22
Logic App, sicurezza e scalabilità
#DOH19 23
Materiale utile
• Session video
https://youtu.be/0ZK1SQ6zkiU
• Demo
https://github.com/OmegaMadLab/StartingWithPoshAzureFunctions
• Documentazione ufficiale
https://docs.microsoft.com/en-us/azure/azure-functions/
• Interazione con Azure AD
https://github.com/eamonoreilly/ManageAzureActiveDirectoryWithPowerShellFunction
• Creazione SendGrid account ed integrazione in Azure Functions
http://www.omegamadlab.com/2019/10/21/using-sendgrid-binding-from-powershell-in-azure-functions/
• Invocazione Az Function con AAD authentication da Logic App
http://www.omegamadlab.com/2019/10/26/calling-an-azure-function-with-azure-ad-authentication-from-a-logic-app/
• Esempio di scalabilità con dedicated plan
https://artisticcheese.wordpress.com/2019/08/20/automation-at-scale-in-azure-with-powershell-azure-functions/
• Scalabilità  PSWorkerInProcConcurrencyUpperBound
https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell#concurrency
#DOH19
THANK YOU!
CODICE FEEDBACK:8F

Automazione serverless con Azure Functions e PowerShell - Marco Obinu - DevOps Heroes 2019

  • 1.
  • 2.
    2 Automazione serverless conAzure Function e PowerShell Marco Obinu @OmegaMadLab
  • 3.
    #DOH19 3 Organizer &sponsors GetLatestVersion.it
  • 4.
    #DOH19 • Advisory Engineer@ Softjam S.p.A. • Geek fino al midollo  @OmegaMadLab marco.obinu@omegamadlab.com http://www.omegamadlab.com https://github.com/OmegaMadLab https://www.linkedin.com/in/marco-obinu-omegamadlab/ https://www.youtube.com/channel/UCpkBeQSscC1iBvpNP4VNTKQ 4 Marco Obinu
  • 5.
    #DOH19 6 Azure Functionse PowerShell: perché? • Piattoforma serverless event-driven • Complementare ad Azure Automation Completa astrazione dal layer hardware Scabilità guidata dagli eventi Paghi per l’effettivo utilizzo
  • 6.
    #DOH19 7 Trigger ebindings Triggers Bindings Blob Binding Direction Binding Direction Queue Blob Input and Output Graph Onedrive Input and Output HTTP Queue Output Graph Email Output Cosmos DB Table Input and Output Graph Event Input and Output Event Grid CosmoDb Input and Output Notification Hubs Output Event Hub Event Hubs Output SendGrid Output MS Graph Event Http Output Service bus Output Service Bus Graph Excel Input and Output SignalR Input and Output Timer https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings Trigger Input binding Output binding
  • 7.
    8 Anatomia di unaPowerShell function
  • 8.
    #DOH19 9 Piani diservizio Resource Consumption plan Premium plan (preview) App Service plan Scale out Event driven Event driven Manual/autoscale Max instances 200 20 10-20 Cold start ✅Yes ❌No ❌No Default time out duration (min) 5 30 30 Max time out duration (min) 10 unbounded unbounded ACU per instance 100 210-840 100-840 Max memory (GB per instance) 1.5 3.5-14 1.75-14 Function apps per plan 100 100 unbounded App Service plans 100 per region 100 per resource group 100 per resource group Storage 1 GB 250 GB 50-1000 GB Vnet integration ❌No ✅Yes ✅Yes https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale
  • 9.
    #DOH19 10 Struttura delfilesystem PSFunctionApp MyFirstFunction run.ps1 function.json MySecondFunction run.ps1 function.json Modules myFirstHelperModule myFirstHelperModule.psd1 myFirstHelperModule.psm1 mySecondHelperModule mySecondHelperModule.psd1 mySecondHelperModule.psm1 local.settings.json host.json requirements.psd1 profile.ps1
  • 10.
    11 Invio report conAz.ResourceGraph e SendGrid
  • 11.
    12 Interrogazione AzSQLDB consqlserver HTTP req HTTP resp
  • 12.
  • 13.
    14 Alert response conAzure Monitor
  • 14.
    #DOH19 15 Integrazione conla rete Consumption plan Premium plan (preview) App Service plan App Service Environment Inbound IP restrictions & private site access ✅Yes ✅Yes ✅Yes ✅Yes Virtual network integration ❌No ✅Yes (Regional) ✅Yes (Regional and Gateway) ✅Yes Virtual network triggers (non-HTTP) ❌No ❌No ✅Yes ✅Yes Hybrid Connections ❌No ✅Yes ✅Yes ✅Yes Outbound IP Restrictions ❌No ❌No ❌No ✅Yes https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
  • 15.
    #DOH19 • Regional vnetintegration 16 Integrazione con la rete https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
  • 16.
    #DOH19 • GW vnetintegration 17 Integrazione con la rete https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
  • 17.
    #DOH19 18 Integrazione conla rete https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options • ASE
  • 18.
    #DOH19 • Hybrid connection 19 Integrazionecon la rete https://docs.microsoft.com/en-us/azure/azure-functions/functions-networking-options
  • 19.
    20 Integrazione con lavnet HTTP req HTTP resp
  • 20.
    #DOH19 21 Sicurezza • Networking •IP restrictions e service endpoint • ASE • Verso l’esterno • Managed Service Identity • Sull’invocazione • Function e master key • Integrazione con authentication providers • Gestione dei dati sensibili • App Settings • Integrazione con Key Vault
  • 21.
  • 22.
    #DOH19 23 Materiale utile •Session video https://youtu.be/0ZK1SQ6zkiU • Demo https://github.com/OmegaMadLab/StartingWithPoshAzureFunctions • Documentazione ufficiale https://docs.microsoft.com/en-us/azure/azure-functions/ • Interazione con Azure AD https://github.com/eamonoreilly/ManageAzureActiveDirectoryWithPowerShellFunction • Creazione SendGrid account ed integrazione in Azure Functions http://www.omegamadlab.com/2019/10/21/using-sendgrid-binding-from-powershell-in-azure-functions/ • Invocazione Az Function con AAD authentication da Logic App http://www.omegamadlab.com/2019/10/26/calling-an-azure-function-with-azure-ad-authentication-from-a-logic-app/ • Esempio di scalabilità con dedicated plan https://artisticcheese.wordpress.com/2019/08/20/automation-at-scale-in-azure-with-powershell-azure-functions/ • Scalabilità  PSWorkerInProcConcurrencyUpperBound https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell#concurrency
  • 23.