I am very new to using AWS services, and relatively new to JS as a whole. I am trying to use putObject to send user data from my website to my s3 bucket. I want any user that enters this site to have their data sent to the bucket. In the HTML of my website, I have have the following JavaScript code, that creates an AWS.S3 object like so:
AWS.config.update({
region: 'us-east-1',
accessKeyID: "MYACCESSKEYID",
secretAccessKey: "MYSECRETACCESSKEY"
});
var s3 = new AWS.S3();
var params = {
Bucket: "my.test.bucket",
Key: <JSON object containing user info>
};
s3.putObject(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
/*
data = {
ETag: "\"6805f2cfc46c0f04559748bb039d69ae\"",
VersionId: "tpf3zF08nBplQK1XLOefGskR7mGDwcDk"
}
*/
});
The access key ID, and the corresponding secret access key, are associated with an IAM user that has the necessary permissions to execute putObject to send an object to the bucket. I am aware that this is not a secure way of doing things, but that is not a concern at the moment. When I try to open the HTML file in the browser, I the error message in the title appears in the browser console. Here is the complete error message that appears in the browser console:
CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
at r (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:70:20163)
at constructor.getCredentials (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:70:20691)
at constructor.<anonymous> (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:71:21119)
at constructor.callListeners (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:23679)
at constructor.emit (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:23419)
at constructor.emitEvent (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:9203)
at constructor.e (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:4845)
at i.runTo (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:75:12863)
at constructor.runTo (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:6501)
at constructor.send (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:6394) "CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
at r (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:70:20163)
at constructor.getCredentials (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:70:20691)
at constructor.<anonymous> (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:71:21119)
at constructor.callListeners (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:23679)
at constructor.emit (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:23419)
at constructor.emitEvent (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:9203)
at constructor.e (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:4845)
at i.runTo (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:75:12863)
at constructor.runTo (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:6501)
at constructor.send (https://sdk.amazonaws.com/js/aws-sdk-2.674.0.min.js:73:6394)"
Please let me know if there is any other information that I can provide.
edit: Using the AWS CLI, I have already attempted to configure my ~/.aws/config file, using the accesskeyID, the secret access key, and the region that I used in the code above