Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to iothub connection string dynamically from custom iot edge module. #7137

Closed
malavvakharia opened this issue Oct 26, 2023 · 8 comments

Comments

@malavvakharia
Copy link

Expected Behavior

Tell us what should happen

Current Behavior

Tell us what happens instead of the expected behavior

Steps to Reproduce

Provide a detailed set of steps to reproduce the bug.
1.
2.
3.
4.

Context (Environment)

Output of iotedge check

Click here

<Paste here between the triple backticks>

Device Information

  • Host OS [e.g. Ubuntu 18.04, Windows Server IoT 2019]:
  • Architecture [e.g. amd64, arm32, arm64]:
  • Container OS [e.g. Linux containers, Windows containers]:

Runtime Versions

  • aziot-edged [run iotedge version]:
  • Edge Agent [image tag (e.g. 1.0.0)]:
  • Edge Hub [image tag (e.g. 1.0.0)]:
  • Docker/Moby [run docker version]:

Note: when using Windows containers on Windows, run docker -H npipe:////./pipe/iotedge_moby_engine version instead

Logs

aziot-edged logs

<Paste here between the triple backticks>

edge-agent logs

<Paste here between the triple backticks>

edge-hub logs

<Paste here between the triple backticks>

Additional Information

Please provide any additional information that may be helpful in understanding the issue.

@malavvakharia
Copy link
Author

malavvakharia commented Oct 26, 2023

Just like we can get the deviceId and moduleId dynamically can we get the iot hub connection string?

#986

IOTEDGE_DEVICEID
IOTEDGE_MODULEID

@malavvakharia malavvakharia changed the title Access to device connection string dynamically from custom iot edge module. Access to iothub connection string dynamically from custom iot edge module. Oct 26, 2023
@ggjjj ggjjj self-assigned this Oct 26, 2023
@ggjjj
Copy link
Contributor

ggjjj commented Oct 26, 2023

do you want to get the connection string in the module?

@malavvakharia
Copy link
Author

do you want to get the connection string in the module?

Hello @ggjjj ,

I want the IOT hub connection string in custom azure module. Not the module connection string.

@ggjjj
Copy link
Contributor

ggjjj commented Oct 26, 2023

You can build it yourself by quering the values of IOTEDGE_IOTHUBHOST and IOTEDGE_DEVICEID from the env var.

connection_string = f"HostName={iot_hub_hostname};DeviceId={device_id};SharedAccessKey="

@malavvakharia
Copy link
Author

malavvakharia commented Oct 30, 2023

Hello @ggjjj ,

So, what is the best practice of defining the SharedAccessKey in code?

And I want iot hub connection string not the device connection string.

Format looks like below:
connection_string = f"HostName={iot_hub_hostname};SharedAccessKeyName=;SharedAccessKey="

@ggjjj
Copy link
Contributor

ggjjj commented Oct 31, 2023

You can set an env variable by setting the output of az iot hub connection-string show and use that in your module to read from

Command Link source - https://learn.microsoft.com/en-us/cli/azure/iot/hub/connection-string?view=azure-cli-latest

@david-emakenemi
Copy link

Hey @malavvakharia did you try @ggjjj suggestion above?

@david-emakenemi
Copy link

Hey @malavvakharia closing this out since no response but feel free to re-open this if you are still experiencing issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants