Iot.searchIndex works fine from CLI, but not from Lambda

0

Having trouble here. Search index works just fine from CLI, but then fails from Lambda...

$ aws iot search-index --index-name "AWS_Things" --query-string "thingName:myThingName"
{
    "things": [ (normal response)]
}

and yet

var params = {
    queryString: "thingName:" + data.Item.thingName,
    indexName: 'AWS_Things'
};
iot.searchIndex(params, function(err, data) {
    if (err) {
        console.log("error from iot.searchIndex");
        console.log(err, err.stack); // an error occurred
    } else {
        console.log("success from iot.searchIndex");
        console.log(data); // successful response
    }
});

The latter produces the error

02:09:20
2019-11-05T02:09:20.595Z 38957129-0e04-43b2-acf6-8b67da6e7ce0 INFO error from iot.searchIndex
02:09:20
2019-11-05T02:09:20.595Z 38957129-0e04-43b2-acf6-8b67da6e7ce0 INFO { ResourceNotFoundException: Not Found at Object.extractError 

What gives? I'm providing the exact information in both places, as verified by console logging, etc. One works, one doesn't. And both users have full IOT access permissions. I don't get it. Any help would be greatly appreciated.

Cyrus
asked 5 years ago271 views
2 Answers
0

Figured it out. I had copied my iot declaration from iotdata with an endpoint. Commenting it out fixed things.

var iotdata = new AWS.IotData({
    endpoint: 'asdfasd-ats.iot.us-east-1.amazonaws.com',
    apiVersion: '2015-05-28'
});

var iot = new AWS.Iot({
 //   endpoint: 'asdfasd-ats.iot.us-east-1.amazonaws.com',
    apiVersion: "2015-05-28"
});
Cyrus
answered 5 years ago
0

Hi Cyrus, glad you got it working. Adding a point of clarification for future readers. API calls to the message broker (pub/sub, shadow; also called the 'data plane') use the custom endpoint and this needs specifying in the AWS.IotData client. Most other APIs are on the control plane, packaged in the AWS.Iot client, and these use a default API endpoint for all customers like iot.us-east-1.amazonaws.com.

AWS
Ryan_B
answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions