0

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');
    });
});
5
  • why do you use AWS sdk in the client side? Commented Mar 5, 2019 at 0:59
  • trying to register subscriber to sns topic Commented Mar 5, 2019 at 1:01
  • you must do it from the server side and configure you aws credentials. Commented Mar 5, 2019 at 1:08
  • im using node, and my aws credentials are in ~/.aws/ Commented Mar 5, 2019 at 1:15
  • please checkout my answer Commented Mar 5, 2019 at 3:33

1 Answer 1

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

    enter image description here

Flow:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.