0
votes

I'm trying to publish on a topic on my AWS Iot from my lambda function which is triggered by an alexa skill. Which class of AWSClient is the right one to do so?

Based on an answer on stackoverflow i know that i need to use the HTTP method to publish from an aws lambda function to aws iot, rather than MQTT. As the class AWSIotDataClient is deprecated, I don't know which class to use. It is suggested by AWS to use AwsIotClientBuilder, which I did but what now?

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

        @Override
        public void refresh() {

        }
    });
2

2 Answers

0
votes

AWSIotDataClient is not deprecated, just the constructors are deprecated, as are the constructors of all AWSClient implementations in favor of builders. You should use AwsClientBuilder.build() to obtain an instance of AWSIotDataClient. Then you can call the publish() method on the AWSIotDataClient instance to publish to your IoT topic.

0
votes
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"));