You'll create an Azure VM with IoT Edge installed.

You'll need Azure Cloud Shell for this lab with an active Azure subscription.

Perform the following steps in the Azure Cloud Shell environment.

  1. Select ‘Bash' from the top left as the environment for your cloud shell.
  2. Add the Azure IoT extension to the cloud shell instance.
    az extension add --name azure-cli-iot-ext 
  3. Create a resource group to hold the cloud infrastructure you'll use for the lab.

Perform these steps in the cloud shell environment.

  1. Create an IoT Hub
    az iot hub create \
    --resource-group iotlab-resources-$UNIQUESTRING \
    --name iotlab-hub-$UNIQUESTRING \
    --sku S1 \
    --partition-count 2   
  2. Register IoT Edge device
    az iot hub device-identity create \
    --hub-name iotlab-hub-$UNIQUESTRING \
    --device-id edge-device-$UNIQUESTRING \

Configure a sample set of inter-communicating modules as the workload to run on the device

# Download
wget \
-O workload.json -q   

# Set
az iot edge set-modules \
  --hub-name iotlab-hub-$UNIQUESTRING \
  --device-id edge-device-$UNIQUESTRING \
  --content workload.json   

Perform these steps in the cloud shell environment.

  1. Setup an SSH key to login to the VM
    ssh-keygen -m PEM -t rsa -b 4096 -q -f ~/.ssh/id_lab -N ""   
  2. Provision a VM and associate with edge device identity
    # Set environment variable
    export CONNSTR=$(az iot hub device-identity show-connection-string \
      --device-id edge-device-$UNIQUESTRING \
      --hub-name iotlab-hub-$UNIQUESTRING \
      -o tsv)   
    # Deploy VM
    az group deployment create \
      --name edgeVm \
      --resource-group iotlab-resources-$UNIQUESTRING \
      --template-uri "" \
      --parameters location=$RGLOC \
      --parameters dnsLabelPrefix=iotedge-vm-$UNIQUESTRING \
      --parameters adminUsername='azureuser' \
      --parameters deviceConnectionString=$CONNSTR \
      --parameters authenticationType='sshPublicKey' \
      --parameters adminPasswordOrKey="$(< ~/.ssh/" | \
        jq .properties.outputs   
  3. Note the ssh command from the value key in previous command's output and use it to login to the VM. For example ssh -i ~/.ssh/id_lab
  4. It can take about 2 minutes for the VM to complete provisioning, enter watch sudo iotedge list in the VM's bash shell and wait for it report modules as running. It is expected to see "command not found" initially. Ctrl+c returns you to the VM's shell.
  5. Type exit in the VM's SSH shell to return the cloud shell environment

Congratulations! You've completed the first lab, we'll use this VM for most other labs in the workshop. We recommend tackling the IoT Edge Troubleshooting Tools labs next.