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 this 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
Filemethod. - 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
Textmethod. - Paste the certificate's public key to the Content field.
- Click Add.
- Choose the
-
-
Click Create.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
Create a broker:
yc iot broker create --name <broker_name>The naming requirements are as follows:
- It must be from 2 to 63 characters long.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with 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 with 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 to the broker a certificate for authentication with 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"
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, 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 name.description: Broker description.labels: Broker labels inkey:valueformat.certificates: List of broker certificates for authentication with 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_certificate_file>"), file("<path_to_second_certificate_file>") ] } output "yandex_iot_core_broker_my_broker" { value = "${yandex_iot_core_broker.my_broker.id}" }For more information about the resources you can create with Terraform, see the relevant provider documentation.
-
Make sure the configuration files are correct.
-
In the command line, navigate to the directory where you created the configuration file.
-
Run a check using this command:
terraform plan
If you described the configuration correctly, the terminal will display a list of the resources being created and their settings. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply -
Confirm creating the resources.
This will create all resources you need in the specified folder. You can check the new resources and their settings 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.