Azure IoT Hub Connection String - Microsoft Exam AZ-220

Retrieve Connection String for Azure IoT Hub - Exam AZ-220

Question

You have just created a device identity in your IoT Hub named mytemphub-001

You want to enable your back-end application to connect to this IoT hub and to access the messages.

You need a connection string which you retrieve by the following CLI command:

az iot hub connection-string show \ --policy-name service \ --name {YourIoTHubName} \ --output table 
Is that the command you should use?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B.

Correct Answer: A.

Option A is CORRECT because to enable back-end applications to connect to your IoT hub you need the service connection string which can be retrieved by the command above.

Option B is incorrect because the command above is actually for retrieving the service connection string needed by the back-end applications.

Field devices would need adevice connection string:

<pre class="brush:java;">az iot hub device-identity connection-string show --hub-name {YourIoTHubName} --device-id MyPythonDevice --output table.

</pre>

Reference:

Yes, the given command is correct and should be used to retrieve the connection string for the service policy of your IoT Hub.

Let's break down the command and understand what each parameter does:

  • "az": This is the Azure CLI (Command-Line Interface) command used to interact with Azure services.
  • "iot hub connection-string show": This command retrieves the connection string for an IoT Hub.
  • "--policy-name service": This specifies that we want to retrieve the connection string for the "service" policy. There are four built-in policies in IoT Hub: "iothubowner", "registryReadWrite", "serviceConnect", and "deviceConnect". The "service" policy is used for back-end applications to access IoT Hub.
  • "--name {YourIoTHubName}": This specifies the name of your IoT Hub, which you need to replace with the actual name of your IoT Hub.
  • "--output table": This specifies the format in which the output will be displayed. In this case, the output will be displayed in a table format.

Once you run this command in the Azure CLI, you should see the connection string for the service policy of your IoT Hub in the output. You can copy and use this connection string in your back-end application to access the IoT Hub and retrieve messages.