title: How can I get a device name from within a IoT Edge Custom module (python)
body: <p><strong>SUMMARY</strong></p>
  
  <p>I don't get the expected hostname from the device when requesting it via python code; I get some container ID</p>
  
  <p><strong>BACKGROUND</strong></p>
  
  <p>When running the following code on Raspbian in python 3:</p>
  
  <pre><code>import socket
  print(socket.gethostname())
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>import platform
  platform.node()
  </code></pre>
  
  <p>...you get the hostname of the machine you're running the code on.
  (That's what I expect)</p>
  
  <p>When doing the same from a Custom IoT Edge module you get some kind of identifier for I think the container?</p>
  
  <p>How can you get the hostname of the system the container is running on within the container module itself?</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>As suggested the Device ID and Module ID are exposed as environment variables:
  IOTEDGE_DEVICEID and IOTEDGE_MODULEID.</p>
  
  <p>So now in python you can do the following:</p>
  
  <pre><code>DEVICEID = os.environ["IOTEDGE_DEVICEID"]
  MODULEID = os.environ["IOTEDGE_MODULEID"]
  </code></pre>
  
  <p>And then use the variables like that in your (python) code down the line.</p>