0

So the read const reads and lists the items in a dynamodb table.

const read = () => {
var AWS = require("aws-sdk");
let awsConfig = {
"region": "us-west-2",
"endpoint": "http://dynamodb.us-west-2.amazonaws.com",
"accessKeyId": "AKIATXDQF3UYRZVGE***", "secretAccessKey": 
"4azvTl67U8QW1id0j8Ck3/rAOqmEp4ajnKF*****"
};
AWS.config.update(awsConfig);

var fullname = document.getElementById('name').value;

const dynamoDB = new AWS.DynamoDB.DocumentClient();

dynamoDB
.scan({
    TableName: "Reservations",
    FilterExpression:
        "#fname = :fname",
    ExpressionAttributeNames:{
        "#fname": "FullName",
    },
    ExpressionAttributeValues: {
        ":fname": fullname,
    },
})
.promise()
.then(data => console.log(data.Items))
.catch(console.error)
}

The function lists out the items in that table, I'm trying to have the function executed and results displayed after an html button is clicked. I've tried encapsulating them in a single callback like:

HTML button:

<button id="button1" type="button" onClick={lookupRoom}> 
    MY RESERVATIONS
  </button>

  <p id="bodyid1"></p>

Javascript:

  const message1 = () => {
   document.getElementById("bodyid1").innerHTML = read();
  };

  function lookupRoom(){
  [message1, read].forEach(x => x());
  }

Any help is appreciated

0 Answers0