问题
Trying to use the AWS SDK for node but I get this error Uncaught Error: Script error for "aws-sdk" Heres my code. I tried using require('aws-sdk'), but the console error than said to use require([],()=>{}) I downloaded both require and aws-sdk from npm
require(['aws-sdk'], (AWS) => {
let email = document.getElementById('footerEmail');
let emailSubmit = document.getElementById('footerButton');
AWS.config.update({ region: 'us-east-1' });
let sns = new AWS.SNS();
let params = {
Protocol: 'email', /* required */
TopicArn: 'arn:aws:sns:us-east-1:274999247491:HouseRoots', /* required */
Endpoint: email.value,
ReturnSubscriptionArn: false
};
console.log('h');
emailSubmit.addEventListener('click', () => {
console.log('h');
sns.subscribe(params, function (err, data) {
if (err) {
email.value = "error occured";
console.log(err);
}
else {
email.value = "confirmation sent";
}
});
console.log('h');
});
});
回答1:
I prepare you a basic sample app, press here.
For run:
- npm install
- node app.js
- open browser localhost:3000/
You must have pre-configured:
aws_credentials file
you must change region in app.js (AWS.config.update({region: 'REGION'});)
the user must have to access SNS
Flow:
来源:https://stackoverflow.com/questions/54993479/uncaught-error-script-error-for-aws-sdk