Azure IoT Hub - Delete module from device

Jan Kubal 20 Reputation points
2023-02-09T12:35:32.96+00:00

I need to create and delete IoT Edge Custom Module programmatically.

To create module I use Azure CLI command az iot edge set-modules and providing json content. This is working fine.

When I want to remove module I have tried the same approach but with content that does not include custom module. And this does not work. Module is still running only Specified in Deployment status changes to No

Is this behavior intended? If yes what is the way to delete module using Azure CLI?

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
{count} votes

2 answers

Sort by: Most helpful
  1. QuantumCache 20,676 Reputation points Moderator
    2023-02-09T17:06:20.6+00:00

    Hello Jan Kubal, As Sander's response has pointed out the recommended way to handle the Automatic deployments in production, please go through that document and do let us know if you have any further queries!

    Regarding your initial query, yes, this behavior is intended. When you use the az iot edge set-modules command to remove a module, it only updates the deployment status of the module to "No" in the deployment manifest.

    The module is still running on the device, but it's not included in the deployment. If you want to delete a module from an IoT Edge device, you need to use the az iot edge remove-modules command. This command stops and removes the module from the device. Here's an example of how to use the command:

    az iot edge remove-modules --device-id [device id] --hub-name [hub name] --module-id [module id]

    • The device ID parameter is case-sensitive.
    • The module ID parameter is the name of the module that you want to remove.

    You can also use Azure IoT Hub Device Twins to manage the modules on your device. You can use the Azure IoT Hub SDK to update the desired properties of the device twin to add or remove modules.

    Deploy Azure IoT Edge modules with Azure CLI

    Use the Azure CLI with the Azure IoT Extension to push an IoT Edge module from your IoT Hub to your IoT Edge device, as configured by a deployment manifest.

    Reference:

    User's image

    1 person found this answer helpful.

  2. Sander van de Velde | MVP 36,951 Reputation points MVP Volunteer Moderator
    2023-02-09T13:35:36.93+00:00

    Hello @Jan Kubal,

    it seems to be resolved already.

    Next time, check other ways to do the same job like the Azure portal so you can cross-check your tooling.

    I recommend actually updating modules using the automatic deployments functionality in production so you can deploy modules at scale. You can also see the history as aa bonus.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.