title: call to getThingShadow does not seem to execute in lambda function
body: <p>I am working on a lambda alexa skill handler that integrates with a thing shadow in aws IoT. My problem is that the call below to iotData.getThingShadow does not seem to execute. None of the console messages are generated within the callback function and the object objState is not getting populated. Here is the code snippet. </p>
  
  <pre><code>   // get the shadow for the home-garage-door
      console.log('Getting thing shadow');
  
      iotData.getThingShadow(params, function(err, data) {
          console.log('Inside of getThingShadow callback');
          if (err){
              //Handle the error here
              console.log('Problem getting the thing shadow');
              console.log(err, err.stack);
              responseString = "I had trouble contacting the garage door, sorry";
          }
          else {
              console.log("Data back from shadow", JSON.stringify(data));
              payload = data.payload;
              objState = JSON.parse(payload);
          }
      });
  
      console.log('After getting the Shadow'); 
  </code></pre>
  
  <p>Below is the log entries generated when I test. Does anyone have any ideas what I may have wrong?</p>
  
  <pre><code>2018-01-14T22:55:15.564Z    fbdde171-f97d-11e7-bc0b-116e508011bd    Getting thing shadow
  2018-01-14T22:55:16.127Z    fbdde171-f97d-11e7-bc0b-116e508011bd    After getting the Shadow
  2018-01-14T22:55:16.165Z    fbdde171-f97d-11e7-bc0b-116e508011bd    objState: undefined
  </code></pre>
  
  <p>Here is the complete code.</p>
  
  <pre><code>/**
      Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  
      Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
  
          http://aws.amazon.com/apache2.0/
  
      or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  */
  
  /**
   *
   */
  
  /**
   * App ID for the skill
   */
   var APP_ID = 'amzn1.ask.skill.XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'; 
  
  
  /**
   * The AlexaSkill prototype and helper functions
   */
  var AlexaSkill = require('./AlexaSkill');
  var AWS = require('aws-sdk');
  
  /**
   * GarageDoorIntentHandler is a child of AlexaSkill.
   * To read more about inheritance in JavaScript, see the link below.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript#Inheritance
   */
  var GarageDoorIntentHandler = function () {
      AlexaSkill.call(this, APP_ID);
  };
  
  // Extend AlexaSkill
  GarageDoorIntentHandler.prototype = Object.create(AlexaSkill.prototype);
  GarageDoorIntentHandler.prototype.constructor = GarageDoorIntentHandler;
  
  GarageDoorIntentHandler.prototype.eventHandlers.onSessionStarted = function (sessionStartedRequest, session) {
      console.log("GarageDoorIntentHandler onSessionStarted requestId: " + sessionStartedRequest.requestId
          + ", sessionId: " + session.sessionId);
      // any initialization logic goes here
  };
  
  GarageDoorIntentHandler.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
      console.log("GarageDoorIntentHandler onLaunch requestId: " + launchRequest.requestId + ", sessionId: " + session.sessionId);
      var speechOutput = "Welcome to the Automated Garage door for Alexa, you can say open the garage door or close the garage door";
      var repromptText = "You can say open or close the garage door";
      response.ask(speechOutput, repromptText);
  };
  
  GarageDoorIntentHandler.prototype.eventHandlers.onSessionEnded = function (sessionEndedRequest, session) {
      console.log("GarageDoorIntentHandler onSessionEnded requestId: " + sessionEndedRequest.requestId
          + ", sessionId: " + session.sessionId);
      // any cleanup logic goes here
  };
  
  GarageDoorIntentHandler.prototype.intentHandlers = {
  
      // register custom intent handlers
      "moveDoorIntent": function (intent, session, response) {
  
          var responseString = ''; 
          var payload = {};
          var objState;
  
          var desiredDoorState = intent.slots.direction.value;
  
          var iotData = new AWS.IotData({endpoint: "XXXXXXXXXXXXXX.iot.us-east-1.amazonaws.com"});
  
          console.log('iotData: ' + JSON.stringify(iotData));
  
          var params = { "thingName" : "&lt;My Thing Name Was Removed for Posting&gt;" };
  
  
          console.log('Intent: ' + JSON.stringify(intent));
  
          // get the shadow for the home-garage-door
          console.log('Getting thing shadow');
  
          iotData.getThingShadow(params, function(err, data) {
              console.log('Inside of getThingShadow callback');
              if (err){
                  //Handle the error here
                  console.log('Problem getting the thing shadow');
                  console.log(err, err.stack);
                  responseString = "I had trouble contacting the garage door, sorry";
              }
              else {
                  console.log("Data back from shadow", JSON.stringify(data));
                  payload = data.payload;
                  objState = JSON.parse(payload);
              }
          });
  
          console.log('After getting the Shadow');
  
          switch(desiredDoorState.toUpperCase()) {
              case 'OPEN':
                  console.log('objState: ' + JSON.stringify(objState));
                  switch (objState.state.reported.status.toUpperCase()) {
                      case 'OPEN': 
                          responseString = "I checked and the door is already open"; 
                          break;
                      case 'CLOSED':
                          responseString = "Ok, I am closing the garage door"; 
                          params.payload = buildObjectState('desired', 'doorActivated', true, 'string');
                          iotData.updateThingShadow(params, function(err, data) {
                              if (err){
                                  //Handle the error here
                                  console.log(err, err.stack);
                                  responseString = "I had trouble doing that, sorry";
                              }
                              else {
                                  responseString = "Ok, I opened the garage door";
                                  console.log("Data back from shadow", data);
                              }
                          });
                  }
                  break;
              case 'CLOSE':
                  break;
              default: 
  
          } // switch
  
          response.tellWithCard(responseString, "Open or Close the Garage Door", responseString);
      },
  
      "getDoorStateIntent": function (intent, session, response) {
          response.tellWithCard("You can say hello to me!", "You can say hello to me!");
      }
  };
  
  
  /**
  *   Helper function to build the state object for the shadow document
  **/
  
  function buildObjectState (section, key, value, format) {
  
      var objState =  {state: {}};
  
      objState.state[section] = {};
      objState.state[section][key] = value;
  
  
      if (format === 'object') {
          return objState;
      } else if (format === 'string') {
          return JSON.stringify(objState);
      } else return; 
  
  }
  
  // Create the handler that responds to the Alexa Request.
  exports.handler = function (event, context) {
  
      console.log('received an event'); 
      // Create an instance of the garageDoorIntentHandler.
      var garageDoorIntentHandler = new GarageDoorIntentHandler();
      garageDoorIntentHandler.execute(event, context);
  };
  </code></pre>