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

Answers:

Answer

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

    enter image description here

Flow:

enter image description here

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.