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
demandé il y a 5 ans277 vues
2 réponses
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
répondu il y a 5 ans
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
répondu il y a 5 ans

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions