我如何在AWS IoT中找到我的个人终端节点?

时间:2019-03-11 21:08:20

标签: amazon-web-services aws-iot

我正在尝试编写一个具有Thing行为的Java应用程序,并在AWS中发布数据。该文档包含以下代码示例:

String clientEndpoint = "<prefix>.iot.<region>.amazonaws.com";       // replace <prefix> and <region> with your own
String clientId = "<unique client id>";                              // replace with your own client ID. Use unique client IDs for concurrent connections.
String certificateFile = "<certificate file>";                       // X.509 based certificate file
String privateKeyFile = "<private key file>";                        // PKCS#1 or PKCS#8 PEM encoded private key file

// SampleUtil.java and its dependency PrivateKeyReader.java can be copied from the sample source code.
// Alternatively, you could load key store directly from a file - see the example included in this README.
KeyStorePasswordPair pair = SampleUtil.getKeyStorePasswordPair(certificateFile, privateKeyFile);
AWSIotMqttClient client = new AWSIotMqttClient(clientEndpoint, clientId, pair.keyStore, pair.keyPassword);

// optional parameters can be set before connect()
client.connect();

我知道什么是clientId以及如何找到我的ID,但是我无法理解clientEndpoint中的内容。

1 个答案:

答案 0 :(得分:0)

致电DescribeEndpoint API

在Java中,这将是:

        AWSIot awsIotClient = AWSIotClientBuilder.defaultClient();
        DescribeEndpointRequest request = new DescribeEndpointRequest().withEndpointType("iot:Data");
        DescribeEndpointResult result = awsIotClient.describeEndpoint(request);
        String endpoint = result.getEndpointAddress();