Microsoft Azure IoT Developer: Retrieve Connection String for Device Identity | Exam AZ-220

Retrieve Connection String for Device Identity

Question

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

You want to enable your back-end applications to connect to this IoT hub in order to get the incoming messages.

You need a connection string to your and you want to retrieve it by the following CLI command:

az iot hub device-identity connection-string show --hub-name {YourIoTHubName} --device-id MyPythonDevice --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: B.

Option A is incorrect because this command is for retrieving the device connection string which is needed for the device itself to connect to the IoT Hub.

For the back-end applications the service connection string is required.

Option B is CORRECT because to enable the back-end application to connect to your IoT hub you need the service connection string which can be retrieved by a command like this:

<pre class="brush:java;">az iot hub connection-string show \

--policy-name service \

--name {YourIoTHubName} \

--output table.

</pre>

Reference:

No, the command given in the question is incorrect.

The command provided in the question is using the wrong device ID, and it is missing the necessary information to retrieve the connection string for a device identity. The correct command to retrieve the connection string for a device identity in an Azure IoT Hub using the Azure CLI is:

css
az iot hub device-identity show-connection-string --hub-name {YourIoTHubName} --device-id mytemphub-001 --output table

In this command, the device-id parameter is set to mytemphub-001, which matches the name of the device identity created in the IoT Hub. Additionally, the show-connection-string parameter is used to retrieve the connection string for the device identity.

The output of this command will be a table that includes the connection string for the specified device identity. This connection string can then be used to connect back-end applications to the IoT Hub in order to receive incoming messages from the device.