Tayyab
Tayyab

Reputation: 349

data is not showing in Dynamodb table

i am working on lex chatbot and want to store user data in dynamodb. here is my databaseManager.js file code

'use strict';
const { v1: uuidv1 } = require('uuid');
const AWS = require('aws-sdk');
const dynamo = new AWS.DynamoDB.DocumentClient();

module.exports.saveBookingToDatabase = async function(Arrival_city, Departure_city, Flight_type, Phone_number){
    console.log('saveBookingToDatabase');

    const item = {};
    item.bookingId = uuidv1();
    item.arrivalCity = Arrival_city;
    item.departureCity = Departure_city;
    item.classType = Flight_type;
    item.phone = Phone_number;

    const params = {
        TableName: 'air_stallion',
        Item: item
    };

    try {
        let result = await dynamo.put(params)
        console.log(`Saving ticket ${JSON.stringify(item)}`);
    return item;  
    } catch(e) {
        throw (e)
    }
}

Table has been created but data is now showing in table

Upvotes: 1

Views: 1735

Answers (1)

Biranchi
Biranchi

Reputation: 16327

The values should not be empty, give some default values to prevent null or empty values.

For Example:

    const item = {};
    item.bookingId = uuidv1();
    item.arrivalCity = Arrival_city || "Arr";
    item.departureCity = Departure_city || "Dept";
    item.classType = Flight_type || "Type";
    item.phone = Phone_number || "Phone";

If the values are okay, then try with

    let result = await dynamo.put(params).promise()

Upvotes: 2

Related Questions