从 lambda 函数发布到 AWS iot 上的主题 [Java]

Publishing to an topic on AWS iot from lambda function [Java]

我正尝试通过我的 lambda 函数在我的 AWS Iot 上发布一个主题,该函数由 alexa 技能触发。 AWSClient 中哪一个 class 是正确的做法?

根据 Whosebug 上的回答,我知道我需要使用 HTTP 方法从 aws lambda 函数发布到 aws iot,而不是 MQTT。由于 class AWSIotDataClient 已弃用,我不知道要使用哪个 class。 AWS 建议使用 AwsIotClientBuilder,我这样做了,但现在呢?

    AWSIotClientBuilder client =  AWSIotClientBuilder.standard();
    client.setEndpointConfiguration(conf);
    client.setCredentials(new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return cred;
        }

        @Override
        public void refresh() {

        }
    });

AWSIotDataClient 没有被弃用,只是构造函数被弃用,所有 AWSClient 实现的构造函数都支持构建器。您应该使用 AwsClientBuilder.build() 来获取 AWSIotDataClient 的实例。然后你可以在 AWSIotDataClient 实例上调用 publish() 方法来发布到你的 IoT 主题。

AWSIotData awsIotDataClient = AWSIotDataClientBuilder.defaultClient(); // add your AWS creds to environment vars to test locally

    awsIotDataClient.publish(new PublishRequest()
                                     .withPayload(ByteBuffer.wrap(("{\"some\":\"message\"}").getBytes()))
                                     .withQos(1)
                                     .withTopic("your/topic"));