0
console.log('starting function');

var dynamodb = new AWS.DynamoDB();
var AWS = require('aws-sdk');

exports.handler = function (e, ctx, callback) {
    var params = {
        Item: {
            "Name": {
                S: "Dalton Warden"
            },
            "PhoneNumber": {
                S: "796-353-1416",
            }
        },
        ReturnConsumedCapacity: "TOTAL",
        TableName: "CustomerInfo"
    };


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

I'm pretty new to lambda and dynamoDB but i'm trying to send data to a table I have set up. I've been through amazon's documentation and looked for similar instances on this site and The formatting looks like it would return the correct JSON but I'm still having trouble. The error I'm getting is Cannot read property 'DynamoDB' of undefined".

1 Answer 1

2

Please change the order of the below statements as mentioned below (first AWS and then dynamodb).

var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB();
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks i'm no longer getting an error but my response is null.
That's because putItem API doesn't return any value. In other words, the variable "data" should be null for put item. Please check the table whether it has the inserted item.
Okay, thank you for explanation. Everything is working.
Good. Please accept the answer if it was helpful. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.