Deploy an Anomaly Detector module to IoT Edge

Learn how to deploy the Cognitive Services Anomaly Detector module to an IoT Edge device. Once it's deployed into IoT Edge, the module runs in IoT Edge together with other modules as container instances. It exposes the exact same APIs as an Anomaly Detector container instance running in a standard docker container environment.

Prerequisites

Create an Anomaly Detector resource

  1. Sign into the Azure portal.

  2. Select Create Anomaly Detector resource.

  3. Enter all required settings:

    Setting Value
    Name Desired name (2-64 characters)
    Subscription Select appropriate subscription
    Location Select any nearby and available location
    Pricing Tier F0 - 10 Calls per second, 20K Transactions per month.
    Or:
    S0 - 80 Calls per second
    Resource Group Select an available resource group
  4. Click Create and wait for the resource to be created. After it is created, navigate to the resource page

  5. Collect configured endpoint and an API key:

    Keys and Endpoint tab in the portal Setting Value
    Overview Endpoint Copy the endpoint. It looks similar to https://<your-resource-name>.cognitiveservices.azure.com/
    Keys API Key Copy 1 of the two keys. It is a 32 alphanumeric-character string with no spaces or dashes, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.

Deploy the Anomaly Detection module to the edge

  1. In the Azure portal, enter Anomaly Detector on IoT Edge into the search and open the Azure Marketplace result.

  2. It will take you to the Azure portal's Target Devices for IoT Edge Module page. Provide the following required information.

    1. Select your subscription.

    2. Select your IoT Hub.

    3. Select Find device and find an IoT Edge device.

  3. Select the Create button.

  4. Select the AnomalyDetectoronIoTEdge module.

    Image of IoT Edge Modules user interface with AnomalyDetectoronIoTEdge link highlighted with a red box to indicate that this is the item to select.

  5. Navigate to Environment Variables and provide the following information.

    1. Keep the value accept for Eula.

    2. Fill out Billing with your Cognitive Services endpoint.

    3. Fill out ApiKey with your Cognitive Services API key.

    Environment variables with red boxes around the areas that need values to be filled in for endpoint and API key

  6. Select Update

  7. Select Next: Routes to define your route. You define all messages from all modules to go to Azure IoT Hub.

  8. Select Next: Review + create. You can preview the JSON file that defines all the modules that get deployed to your IoT Edge device.

  9. Select Create to start the module deployment.

  10. After you complete module deployment, you'll go back to the IoT Edge page of your IoT hub. Select your device from the list of IoT Edge devices to see its details.

  11. Scroll down and see the modules listed. Check that the runtime status is running for your new module.

To troubleshoot the runtime status of your IoT Edge device, consult the troubleshooting guide

Test Anomaly Detector on an IoT Edge device

You'll make an HTTP call to the Azure IoT Edge device that has the Azure Cognitive Services container running. The container provides REST-based endpoint APIs. Use the host, http://<your-edge-device-ipaddress>:5000, for module APIs.

If your edge device does not already allow inbound communication on port 5000, you will need to create a new inbound port rule.

For an Azure VM, this can set under Virtual Machine > Settings > Networking > Inbound port rule > Add inbound port rule.

There are several ways to validate that the module is running. Locate the External IP address and exposed port of the edge device in question, and open your favorite web browser. Use the various request URLs below to validate the container is running. The example request URLs listed below are http://<your-edge-device-ipaddress:5000, but your specific container may vary. Keep in mind that you need to use your edge device's External IP address.

Request URL Purpose
http://<your-edge-device-ipaddress>:5000/ The container provides a home page.
http://<your-edge-device-ipaddress>:5000/status Also requested with GET, this verifies if the api-key used to start the container is valid without causing an endpoint query. This request can be used for Kubernetes liveness and readiness probes.
http://<your-edge-device-ipaddress>:5000/swagger The container provides a full set of documentation for the endpoints and a Try it out feature. With this feature, you can enter your settings into a web-based HTML form and make the query without having to write any code. After the query returns, an example CURL command is provided to demonstrate the HTTP headers and body format that's required.

Container's home page

Next steps