简体   繁体   中英

Uncaught Error: Script error for “aws-sdk”

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');
    });
});

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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM