question

Seth avatar image
Seth asked

AWS IoT SDK used inside Lambda function - no error but payload is not published

Hello,

I have built an Alexa skill that invokes an AWS IoT object to publish a payload to a specific topic - but I do not see any payloads published from within the Test section of the AWS IoT dashboard.

  1. The skill successfully exits when tested - no errors indicated anywhere inside the code.
  2. After the skill exits a test, I don't see the payload in the Test area of the AWS IoT dashboard
    1. The IoTData object is initialized without any errors:
      var AWS = require('aws-sdk');
      var iotdata = new AWS.IotData({endpoint: '************.iot.us-west-2.amazonaws.com'});
    2. I receive no errors from the following code:
      var params = {
                  topic: 'b827ebac1bba/commands',
                  payload: '0',
                  qos: 0
              };
              iotdata.publish(params);
      
  3. The IAM policy role attached to the Lambda function allows iot:Publish:
  4. {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "logs:CreateLogStream",
                    "logs:PutLogEvents"
                ],
                "Resource": "arn:aws:logs:*:*:*"
            },
            {
                "Effect": "Allow",
                "Action": "iot:Publish",
                "Resource": "*"
            },
            {
                "Effect": "Allow",
                "Action": "logs:CreateLogGroup",
                "Resource": "arn:aws:logs:*:*:*"
            }
        ]
    }

Any idea on what I should try next?

lambdaaws iot
1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Seth avatar image Seth commented ·

UPDATE: When I include a callback function:

iotdata.publish(params, function (err, data) {
            if (err) console.log(err, err.stack); // an error occurred
            else     console.log(data);           // successful response
        });<br>

the lambda function runs until it times out. Also, I have increased the timeout period to 30 seconds.

0 Likes 0 ·

1 Answer

Jason@Amazon avatar image
Jason@Amazon answered

As this issue is more related to AWS than Alexa, I would suggest posting on the AWS developer forum for further assistance over here.

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.