Creating an alias in Yandex IoT Core
Aliases are linked to specific devices. To create an alias, you need to find the device ID or name.
Note
You can only use the $me
system alias for the $monitoring/<device_ID>/json
topic.
To create an alias:
- In the management console
, select a folder where you wish to create an alias. - Select IoT Core.
- Select the required registry from the list.
- On the left side of the window, select the Devices section.
- Click
to the right of the appropriate device name and select Edit from the drop-down list. - Add an alias:
- Click Add alias.
- Fill in the fields: enter an alias (e.g.,
events
) and topic type after$devices/<device_ID>
(e.g.,events
).
You can now useevents
instead of$devices/<device_ID>/events
. - Repeat the steps for each alias you add.
- Click Save.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
Create an alias:
yc iot device add-topic-aliases arenak5ciqss********
--topic-aliases commands='$devices/arenak5ciqss********/commands'
Result:
id: arenak5ciqss********
registry_id: arenou2oj4ct********
created_at: "2019-09-16T12:32:48.911Z"
name: second
topic_aliases:
commands: $devices/arenak5ciqss********/commands
You can also add an alias when creating a device. To do this, instead of a unique ID, specify the {id}
in the device topic, since the unique ID is not known yet:
yc iot device create
--registry-name <registry_name>
--name <device_name>
--topic-aliases <alias_name>='$devices/{id}/<events,_state,_commands_or_config>'
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To add an alias to a device created usingTerraform:
-
In the configuration file, describe the parameters of the resources you want to create:
yandex_iot_core_registry
: Device properties:registry_id
: ID of the registry where the device was created.name
: Device name.description
: Device description.aliases
: Topic aliases.
Here is an example of the resource structure in the configuration file:
resource "yandex_iot_core_device" "my_device" { registry_id = "<registry_ID>" name = "<device_name>" description = "test device for terraform provider documentation" aliases = { "some-alias1/subtopic" = "$devices/{id}/events/somesubtopic", "some-alias2/subtopic" = "$devices/{id}/events/aaa/bbb", } ... }
For more information about the
yandex_iot_core_device
parameters in Terraform, see the relevant provider documentation . -
In the command line, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and click Enter.You can verify device aliases in the management console
or using the following CLI command:yc iot device get <device_name>
To create an alias, use the create REST API method for the Device resource or the DeviceService/Create gRPC API call.