I'm trying to implement DynamoDB in a Javascript file. I tried out multiple tutorials in succession to no avail. All I'm trying to do is make a query from within my Javascript code (which is being run in an HTML page). Unfortunately, my code doesn't even get up to that. It throws me errors when I try to require AWS-SDK. I installed aws-sdk with Node.js. After being confused by multiple tutorials, I ended up with the following code:
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="http://requirejs.org/docs/release/2.2.0/r.js"></script>
<script src="boom.js"></script>
</head>
<body></body>
</html>
JavaScript (boom.js):
require(['aws-sdk'], function (foo) {
var CONF = require("./super_secure_conf.json");
var AWS = require("aws-sdk");
function init(){
AWS.config = new AWS.Config({
access_key_id: CONF.AWS_ACCESS_KEY_ID,
secretAccessKey: CONF.AWS_SECRET_ACCESS_KEY,
region: "us-east-1"
});
DynamoDB = new AWS.DynamoDB();
}
});
The file "super_secret_conf.json" is a JSON file containing my AWS Credentials. I tried storing the credentials at ~/.aws/credentials previously, but that wasn't working. (Should credentials be a folder or file? I had tried saving my credentials in a blank file – without any extension. Just thought I'd mention.) So I followed another tutorial, which said to use the JSON method (and I am aware that it is very insecure) which is what you see here. I still get an error though:
Error: Module name "super_secure_conf.json" has not been loaded yet for context: _. Use require([])
All and any help is greatly appreciated.