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
질문됨 5년 전279회 조회
2개 답변
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
답변함 5년 전
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
답변함 5년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인