Skip to content

Commit a24cc5d

Browse files
Merge pull request #114594 from VasiyaKrishnan/AzureSqlEdgeTutorial
SQL Edge- Added tutorial to be released for Build
2 parents 8f6dbf0 + 11c50d1 commit a24cc5d

File tree

7 files changed

+559
-397
lines changed

7 files changed

+559
-397
lines changed

articles/azure-sql-edge/configure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ traceflag2 = 1204
112112
## Next step
113113

114114
- [Connect to Azure SQL Edge](connect.md)
115-
- [Building an end-to-end IoT solution with SQL Edge](onnx-demo.md)
115+
- [Building an end-to-end IoT solution with SQL Edge](deploy-azure-resources.md)
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
---
2+
title: Set up resources and software for the tutorial
3+
description: In this section, we will install pre-requisite software and set up required Azure resources for the tutorial
4+
keywords:
5+
services: sql-database-edge
6+
ms.service: sql-database-edge
7+
ms.topic: conceptual
8+
author: VasiyaKrishnan
9+
ms.author: vakrishn
10+
ms.reviewer: sstein
11+
ms.date: 05/19/2020
12+
---
13+
# Install software and set up resources for the tutorial
14+
In this tutorial, you will be predicting iron ore impurities as a % of Silica in Azure SQL Edge. Before you proceed with the tutorial, ensure you have an active Azure subscription and you have installed the below pre-requisite software.
15+
16+
## Pre-requisite software to be installed
17+
1. If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/).
18+
2. Install [Visual Studio Professions/Enterprise](https://visualstudio.microsoft.com/vs/)
19+
3. Install [PowerShell 3.6.8](https://www.python.org/downloads/release/python-368/)
20+
* Windows x86-x64 Executable Installer
21+
* Ensure to add python path to the PATH environment variables
22+
4. Install ["Microsoft Visual C++ 14.0" and build tools for Visual Studio](https://visualstudio.microsoft.com/downloads/) - Download can be located under "Tools For Visual Studio 2019"
23+
5. Install [Microsoft ODBC Driver 17 for SQL Server](https://www.microsoft.com/download/details.aspx?id=56567)
24+
6. Install [Azure Data Studio](/sql/azure-data-studio/download-azure-data-studio/)
25+
7. Open Azure Data Studio and configure Python for Notebooks. Details on how this can be accessed [here](/sql/azure-data-studio/sql-notebooks#configure-python-for-notebooks).This step can take several minutes.
26+
8. Install latest version of [Azure CLI](https://github.com/Azure/azure-powershell/releases/tag/v3.5.0-February2020)
27+
9. The below scripts require that the AZ PowerShell to be at the latest version (3.5.0, Feb 2020)
28+
29+
## Deploying Azure resources using PowerShell Script
30+
31+
Now, deploy Azure resources required for running the end to end scenario for Azure SQL Edge. These can be deployed either by using the PowerShell script below or through the Azure portal. For the purpose of this demo, we will be using the PowerShell Script.
32+
33+
1. Importing modules needed to run the below PowerShell script.
34+
```powershell
35+
Import-Module Az.Accounts -RequiredVersion 1.7.3
36+
Import-Module -Name Az -RequiredVersion 3.5.0
37+
Import-Module Az.IotHub -RequiredVersion 2.1.0
38+
Import-Module Az.Compute -RequiredVersion 3.5.0
39+
az extension add --name azure-cli-iot-ext
40+
az extension add --name azure-cli-ml
41+
```
42+
2. Now, let us declare the variables required for the script to run.
43+
```powershell
44+
$ResourceGroup = "<name_of_the_resource_group>"
45+
$IoTHubName = "<name_of_the_IoT_hub>"
46+
$location = "<location_of_your_Azure_Subscription>"
47+
$SubscriptionName = "<your_azure_subscription>"
48+
$NetworkSecGroup = "<name_of_your_network_security_group>"
49+
$StorageAccountName = "<name_of_your_storage_account>"
50+
```
51+
3. Declaring rest of the variables.
52+
```powershell
53+
$IoTHubSkuName = "S1"
54+
$IoTHubUnits = 4
55+
$EdgeDeviceId = "IronOrePredictionDevice"
56+
$publicIpName = "VMPublicIP"
57+
$imageOffer = "iot_edge_vm_ubuntu"
58+
$imagePublisher = "microsoft_iot_edge"
59+
$imageSku = "ubuntu_1604_edgeruntimeonly"
60+
$AdminAcc = "iotadmin"
61+
$AdminPassword = ConvertTo-SecureString "IoTAdmin@1234" -AsPlainText -Force
62+
$VMSize = "Standard_DS3"
63+
$NetworkName = "MyNet"
64+
$NICName = "MyNIC"
65+
$SubnetName = "MySubnet"
66+
$SubnetAddressPrefix = "10.0.0.0/24"
67+
$VnetAddressPrefix = "10.0.0.0/16"
68+
$MyWorkSpace = "SQLDatabaseEdgeDemo"
69+
$containerRegistryName = $ResourceGroup + "ContRegistry"
70+
```
71+
4. To begin creation of assets, let us log in into Azure.
72+
```powershell
73+
Login-AzAccount
74+
75+
az login
76+
```
77+
5. Next, set the Azure Subscription ID.
78+
```powershell
79+
Select-AzSubscription -Subscription $SubscriptionName
80+
az account set --subscription $SubscriptionName
81+
```
82+
6. Check and create a resource group for running the demo.
83+
```powershell
84+
$rg = Get-AzResourceGroup -Name $ResourceGroup
85+
if($rg -eq $null)
86+
{
87+
Write-Output("Resource Group $ResourceGroup does not exist, creating Resource Gorup")
88+
New-AzResourceGroup -Name $ResourceGroup -Location $location
89+
}
90+
else
91+
{
92+
Write-Output ("Resource Group $ResourceGroup exists")
93+
}
94+
```
95+
7. Check and create a Storage account and Storage account container in the Resource Group. Also create a container within the storage account and upload the zipped dacpac file. Generate a SAS URL for the file.
96+
```powershell
97+
$sa = Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName
98+
if ($sa -eq $null)
99+
{
100+
New-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName -SkuName Standard_LRS -Location $location -Kind Storage
101+
$sa = Get-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageAccountName
102+
$storagekey = Get-AzStorageAccountKey -ResourceGroupName $ResourceGroup -Name $StorageAccountName
103+
$storageContext = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storagekey[0].Value
104+
New-AzStorageContainer -Name "sqldatabasedacpac" -Context $storageContext
105+
}
106+
else
107+
{
108+
Write-Output ("Storage Account $StorageAccountName exists in Resource Group $ResourceGroup")
109+
}
110+
```
111+
8. Upload the Database Dacpac file to the Storage account and generate a SAS URL for the blob. **Note down the SAS URL for the database dacpac blob.**
112+
```powershell
113+
$file = Read-Host "Please Enter the location to the zipped Database DacPac file:"
114+
Set-AzStorageBlobContent -File $file -Container "sqldatabasedacpac" -Blob "SQLDatabasedacpac.zip" -Context $sa.Context
115+
$DacpacFileSASURL = New-AzStorageBlobSASToken -Container "sqldatabasedacpac" -Blob "SQLDatabasedacpac.zip" -Context $sa.Context -Permission r -StartTime (Get-Date).DateTime -ExpiryTime (Get-Date).AddMonths(12) -FullUri
116+
```
117+
9. Check and Create an Azure Container Registry within this Resource Group.
118+
```powershell
119+
$containerRegistry = Get-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName
120+
if ($containerRegistry -eq $null)
121+
{
122+
New-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName -Sku Standard -Location $location -EnableAdminUser
123+
$containerRegistry = Get-AzContainerRegistry -ResourceGroupName $ResourceGroup -Name $containerRegistryName
124+
}
125+
else
126+
{
127+
Write-Output ("Container Registry $containerRegistryName exists in Resource Group $ResourceGroup")
128+
}
129+
```
130+
10. Push the ARM/AMD docker images to the Container Registry.
131+
```powershell
132+
$containerRegistryCredentials = Get-AzContainerRegistryCredential -ResourceGroupName $ResourceGroup -Name $containerRegistryName
133+
134+
$amddockerimageFile = Read-Host "Please Enter the location to the amd docker tar file:"
135+
$armdockerimageFile = Read-Host "Please Enter the location to the arm docker tar file:"
136+
$amddockertag = $containerRegistry.LoginServer + "/silicaprediction" + ":amd64"
137+
$armdockertag = $containerRegistry.LoginServer + "/silicaprediction" + ":arm64"
138+
139+
docker login $containerRegistry.LoginServer --username $containerRegistryCredentials.Username --password $containerRegistryCredentials.Password
140+
141+
docker import $amddockerimageFile $amddockertag
142+
docker push $amddockertag
143+
144+
docker import $armdockerimageFile $armdockertag
145+
docker push $armdockertag
146+
```
147+
11. Check and create the network security Group within the Resource Group.
148+
```powershell
149+
$nsg = Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Name $NetworkSecGroup
150+
if($nsg -eq $null)
151+
{
152+
Write-Output("Network Security Group $NetworkSecGroup does not exist in the resource group $ResourceGroup")
153+
154+
$rule1 = New-AzNetworkSecurityRuleConfig -Name "SSH" -Description "Allow SSH" -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 22
155+
$rule2 = New-AzNetworkSecurityRuleConfig -Name "SQL" -Description "Allow SQL" -Access Allow -Protocol Tcp -Direction Inbound -Priority 101 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 1600
156+
New-AzNetworkSecurityGroup -Name $NetworkSecGroup -ResourceGroupName $ResourceGroup -Location $location -SecurityRules $rule1, $rule2
157+
158+
$nsg = Get-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup -Name $NetworkSecGroup
159+
}
160+
else
161+
{
162+
Write-Output ("Network Security Group $NetworkSecGroup exists in the resource group $ResourceGroup")
163+
}
164+
```
165+
12. Create an Edge enabled VM, which will act as an Edge Device.
166+
```powershell
167+
$AzVM = Get-AzVM -ResourceGroupName $ResourceGroup -Name $EdgeDeviceId
168+
If($AzVM -eq $null)
169+
{
170+
Write-Output("The Azure VM with Name- $EdgeVMName is not present in the Resource Group- $ResourceGroup ")
171+
172+
$SingleSubnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix
173+
$Vnet = New-AzVirtualNetwork -Name $NetworkName -ResourceGroupName $ResourceGroup -Location $location -AddressPrefix $VnetAddressPrefix -Subnet $SingleSubnet
174+
$publicIp = New-AzPublicIpAddress -Name $publicIpName -ResourceGroupName $ResourceGroup -AllocationMethod Static -Location $location
175+
$NIC = New-AzNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroup -Location $location -SubnetId $Vnet.Subnets[0].Id -NetworkSecurityGroupId $nsg.Id -PublicIpAddressId $publicIp.Id
176+
177+
178+
##Set-AzNetworkInterfaceIpConfig -Name "ipconfig1" -NetworkInterface $NIC -PublicIpAddress $publicIp
179+
180+
$Credential = New-Object System.Management.Automation.PSCredential ($AdminAcc, $AdminPassword);
181+
182+
$VirtualMachine = New-AzVMConfig -VMName $EdgeDeviceId -VMSize $VMSize
183+
$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Linux -ComputerName $EdgeDeviceId -Credential $Credential
184+
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
185+
$VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName $imagePublisher -Offer $imageOffer -Skus $imageSku -Version latest
186+
$VirtualMachine = Set-AzVMPlan -VM $VirtualMachine -Name $imageSku -Publisher $imagePublisher -Product $imageOffer
187+
188+
$AzVM = New-AzVM -ResourceGroupName $ResourceGroup -Location $location -VM $VirtualMachine -Verbose
189+
$AzVM = Get-AzVM -ResourceGroupName $ResourceGroup -Name $EdgeDeviceId
190+
191+
}
192+
else
193+
{
194+
Write-Output ("The Azure VM with Name- $EdgeDeviceId is present in the Resource Group- $ResourceGroup ")
195+
}
196+
```
197+
13. Create an IoT Hub within the resource group.
198+
```powershell
199+
$iotHub = Get-AzIotHub -ResourceGroupName $ResourceGroup -Name $IoTHubName
200+
If($iotHub -eq $null)
201+
{
202+
Write-Output("IoTHub $IoTHubName does not exists, creating The IoTHub in the resource group $ResourceGroup")
203+
New-AzIotHub -ResourceGroupName $ResourceGroup -Name $IoTHubName -SkuName $IoTHubSkuName -Units $IoTHubUnits -Location $location -Verbose
204+
}
205+
else
206+
{
207+
Write-Output ("IoTHub $IoTHubName present in the resource group $ResourceGroup")
208+
}
209+
```
210+
14. Add an Edge Device to the IoT Hub. This step only creates the device digital identity
211+
```powershell
212+
$deviceIdentity = Get-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId
213+
If($deviceIdentity -eq $null)
214+
{
215+
Write-Output("The Edge Device with DeviceId- $EdgeDeviceId is not registered to the IoTHub- $IoTHubName ")
216+
Add-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId -EdgeEnabled
217+
}
218+
else
219+
{
220+
Write-Output ("The Edge Device with DeviceId- $EdgeDeviceId is registered to the IoTHub- $IoTHubName")
221+
}
222+
$deviceIdentity = Get-AzIotHubDevice -ResourceGroupName $ResourceGroup -IotHubName $IoTHubName -DeviceId $EdgeDeviceId
223+
```
224+
15. Get the device Primary connection String. This would be needed later for the VM. The next command uses Azure CLI for deployments.
225+
```powershell
226+
$deviceConnectionString = az iot hub device-identity show-connection-string --device-id $EdgeDeviceId --hub-name $IoTHubName --resource-group $ResourceGroup --subscription $SubscriptionName
227+
$connString = $deviceConnectionString[1].Substring(23,$deviceConnectionString[1].Length-24)
228+
$connString
229+
```
230+
16. Update the connection string in the IoT Edge Config File on the Edge Device. The next commands use Azure CLI for deployments.
231+
```powershell
232+
$script = "/etc/iotedge/configedge.sh '" + $connString + "'"
233+
az vm run-command invoke -g $ResourceGroup -n $EdgeDeviceId --command-id RunShellScript --script $script
234+
```
235+
17. Create an Azure Machine learning workspace within the Resource Group
236+
```powershell
237+
az ml workspace create -w $MyWorkSpace -g $ResourceGroup
238+
```
239+
240+
## Next Steps
241+
242+
- [Setting up IoT Edge modules and connections](set-up-iot-edge-modules.md)

0 commit comments

Comments
 (0)