-1

My lambda function uses the method

ddb.putItem(params, function(err, data) {
 if (err) console.log(err, err.stack); // an error occurred
 else     console.log("SUBMITTED DATA");           // successful response
 });

with my params being correctly formatted to my table. No error is shown in my logs, however "SUBMITTED DATA" does not appear in the logs either, and the data is not put into my DynamoDB table. Any idea on what might be causing this problem? Heres my complete function:

const TrackHabitIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'TrackHabitIntent';
},
handle(handlerInput) {
ddb.putItem(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log("SUBMITTED DATA");           // successful response

});
const speechText = "That's awesome! I'll add today to your streak of 4 days";



return handlerInput.responseBuilder
  .speak(speechText)
  .reprompt(speechText)
  .withSimpleCard('Hello World', speechText)
  .getResponse();
}};

exports.handler =  function (event, context) {
if (!skill) {
skill = Alexa.SkillBuilders.custom()
  .addRequestHandlers(
    LaunchRequestHandler,
    HelpIntentHandler,
    HelpMeIntentHandler,
    TrackHabitIntentHandler,
    NewHabitIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler,
  )
  .addErrorHandlers(ErrorHandler)
  .create();
 }
 return response;
 };

Thanks

kumail
  • 1,331
  • 4
  • 13
  • 19

1 Answers1

1

Please check this code to add data in dynamoDB that can help you.

let putParams = {
        TableName: tableName,
        Item: {
          'Id': {
            S: Id
          },
          'name': {
            S: name
          }
        },
        ConditionExpression: 'attribute_exists(Id)'
      };

      dynamoDb.putItem(putParams, function (err, data) {
        if (err) {
          console.log('failure:put data from Dynamo error', err);
          reject(err);
        } else {
          console.log('success:put data from Dynamo data');
          resolve(data);
        }
      });
IftekharDani
  • 3,619
  • 1
  • 16
  • 21