未捕获的错误:“ aws-sdk”的脚本错误

时间:2019-03-05 00:03:03

标签: javascript node.js amazon-web-services aws-sdk

尝试将AWS开发工具包用于节点,但出现此错误未捕获的错误:“ aws-sdk”的脚本错误 这是我的代码。我尝试使用require('aws-sdk'),但是控制台错误不是说使用require([],()=> {}) 我从npm下载了require和aws-sdk

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 个答案:

答案 0 :(得分:1)

我为您准备了一个基本的示例应用press here

要运行:

  • npm安装
  • 节点app.js
  • 打开浏览器localhost:3000 /

您必须已预先配置:

  • aws_credentials文件

  • 您必须更改app.js中的区域( AWS.config.update({region:'REGION'});

    < / li>
  • 用户必须访问SNS

    enter image description here

流量:

enter image description here