I'm new to working with databases through scripting, so I was learning with this tutorial on how to access DynamoDB with HTML and JavaScript. I successfully created the Movies table and added the one item, but I'm running into an error with reading the item. Below is the example script for reading an item with my credentials.
<html>
<head>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.7.16.min.js">
</script>
<script>
AWS.config.update({
region: "us-east-2",
endpoint: 'http://localhost:8000',
accessKeyId: "...",
secretAccessKey: "..."
});
var docClient = new AWS.DynamoDB.DocumentClient();
function readItem() {
var table = "Movies";
var year = 2015;
var title = "The Big New Movie";
var params = {
TableName: table,
Key:{
"year": year,
"title": title
}
};
docClient.get(params, function(err, data) {
if (err) {
document.getElementById('textarea').innerHTML = "Unable to read item: " + "\n" + JSON.stringify(err, undefined, 2);
} else {
document.getElementById('textarea').innerHTML = "GetItem succeeded: " + "\n" + JSON.stringify(data, undefined, 2);
}
});
}
</script>
</head>
<body>
<input id="readItem" type="button" value="Read Item" onclick="readItem();" />
<br><br>
<textarea readonly id= "textarea" style="width:400px; height:800px">
</textarea>
</body>
</html>
After clicking the button in the HTML file, I get this error:
Unable to read item:
{
"message": "Network Failure",
"code": "NetworkingError",
"time": "2017-08-02T14:32:36.416Z",
"region": "us-east-2",
"hostname": "localhost",
"retryable": true
}
I have also tried query and scan with the demo code and I get the same result. The only idea I have is the local host port might not be correct, but I'm not sure how to check what port I can use instead. I've also read a few forum threads about similar issues, but they used the database with another Amazon web service. Any other help would be appreciated!