Creating a broker
Note
The broker is at the Preview stage.
-
In the management console
, select the folder where you want to create a broker. -
Select IoT Core.
-
In the left-hand panel, select Brokers.
-
Click Create broker.
-
Under General information, specify:
-
Broker Name, e.g.,
my-broker
. -
(Optional) Description: Additional information about the broker.
-
(Optional) Password if you are going to use it instead of a certificate to access the broker. To create a password, you can use the password generator
.Note
Make sure to save your password, as you will need it for authentication.
-
(Optional) To assign a label to the broker, fill in the Key and Value fields and click Add label.
-
-
(Optional) Add a certificate:
-
To add a file:
- Choose the
File
method. - Click Attach file.
- Select the file with the public key of the certificate and click Open.
- Click Add.
- Choose the
-
To add text:
- Choose the
Text
method. - Paste the public key of the certificate to the Content field.
- Click Add.
- Choose the
-
-
Click Create.
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 a broker:
yc iot broker create --name <broker_name>
The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
Result:
id: b91ki3851h********** folder_id: aoek49ghmk********* created_at: "2022-05-28T11:29:42.420Z" name: <broker_name> status: ACTIVE
-
(Optional) Assign the broker a password for authentication using a username and password:
yc iot broker password add --broker-name <broker_name>
You will be prompted to enter a password. Password requirements:
- The password must contain numbers, upper-case and lower-case letters, and special characters.
- It must be at least 14 characters long.
Result:
broker_id: b91ki3851h********** id: aoek49ghmk********* created_at: "2022-05-28T11:32:42.420Z"
-
(Optional) Add a certificate to the broker for authentication using certificates:
yc iot broker certificate add \ --broker-name <broker_name> \ --certificate-file <certificate>
Where:
--broker-name
: Broker name--certificate-file
: Path to the public key of the certificate, such ascert.pem
.
Result:
broker_id: b91ki3851h********** fingerprint: 1f21cf6d0183d**** certificate_data: | -----BEGIN CERTIFICATE----- MIIEpDCCAow... -----END CERTIFICATE----- created_at: "2023-07-11T16:20:53.466370019Z"
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.
Note
To add certificates to a broker, generate them in advance.
To create a broker:
-
In the configuration file, describe the parameters of the resource to create:
yandex_iot_core_broker
: Broker parameters:name
: Broker namedescription
: Broker descriptionlabels
: Broker labels inkey:value
formatcertificates
: List of broker certificates for authentication using certificates.
Here is an example of the resource structure in the configuration file:
resource "yandex_iot_core_broker" "my_broker" { name = "test-broker" description = "test broker for terraform provider documentation" labels = { test-label = "label-test" } certificates = [ file("<path_to_first_file_with_certificate>"), file("<path_to_second_file_with_certificate>") ] } output "yandex_iot_core_broker_my_broker" { value = "${yandex_iot_core_broker.my_broker.id}" }
For more information about resources you can create using Terraform, see the provider documentation
. -
Make sure the configuration files are correct.
-
In the command line, go to the directory where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration is described correctly, the terminal will display a list of created resources and their parameters. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply
-
Confirm that you want to create the resources.
All the resources you need will then be created in the specified folder. You can check the new resources and their configuration using the management console
or this CLI command:yc iot broker list
-
To create a broker, use the create REST API method for the Broker resource or the BrokerService/Create gRPC API call.