By using AWS re:Post, you agree to the Terms of Use

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


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

2019-11-05T02:09:20.595Z 38957129-0e04-43b2-acf6-8b67da6e7ce0 INFO error from iot.searchIndex
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.

asked 3 years ago10 views
2 Answers

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: '',
    apiVersion: '2015-05-28'

var iot = new AWS.Iot({
 //   endpoint: '',
    apiVersion: "2015-05-28"
answered 3 years ago

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

answered 3 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