node.js - 无法从任何提供商 Nodemailer aws 加载凭证

标签 node.js amazon-web-services amazon-ec2 aws-sdk nodemailer

有一段时间我一直在尝试寻找问题的答案。我一直在尝试使用nodemailer和nodemailer-ses-transport。这是 Node 邮件程序代码:

var cfg = require('../config/config');
var nodemailer = require('nodemailer');
var aws   = require('nodemailer-ses-transport');

var transporter = nodemailer.createTransport(aws({
  accessKeyId: cfg.KEY,
  secretAccessKey: cfg.SKEY,
  default_region: cfg.REG,
  ratelimit: 5
}));

router.post('/signup', function(req, res, next){
  passport.authenticate('local.signup', function(err, user, info) {
    if (err) { return next(err); }
    // Redirect if it fails

    if (!user) { return res.redirect('/signup'); }
    req.logIn(user, function(err) {
     if (err) { return next(err); }
      // Redirect and send email if it succeeds

      var date = Date.now();

      var mailOptions = {
        from: cfg.USER,
        to: req.body.email,
        date: date,
        subject: 'Welcome to Shapevibe',
        html: '<p> Welcome to Shapevibe!</p>'
      };
      transporter.sendMail(mailOptions, function(error, info){
        if(error){
          console.log(error);
        }
        else{
          console.log('Message Sent: ' + info);
        }
      });
      return res.redirect('/api/dashboard/viber' + user._id);
    });

    // flash success and redirect to viber dashboard
    req.flash('success', 'Thank you for signing up. You will recieve 
an email shortly');
 })(req, res, next);
});

在配置文件中:

var config = {};
config.USER = 'Shapevibe@gmail.com';
config.KEY = 'xxxxxxxxxxx';
config.SKEY = 'xxxxx';
config.REG = 'us-west-2c';
module.exports = config;

当我运行 npm start 时,它可以正常连接到服务器。但是,当我测试登录页面 I 时,路由工作正常,但电子邮件未发送,并且出现此错误:

{ CredentialsError: Missing credentials in config
    at IncomingMessage.<anonymous> 
(/home/ubuntu/ShapeVibe/Website/node_modules/aws-sdk/lib/util.js:864:34)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickDomainCallback 
(internal/process/next_tick.js:128:9)
  message: 'Missing credentials in config',
  retryable: false,
  time: 2017-08-09T19:13:54.105Z,
  code: 'CredentialsError',
  originalError: 
   { message: 'Could not load credentials from any providers',
     retryable: false,
     time: 2017-08-09T19:13:54.105Z,
     code: 'CredentialsError' } }

I have been researching a solution for a long time now, and nothing has seemed to work. I looked at almost everything similar on Stackoverflow and nothing has helped. Please let me know if you have any ideas.

最佳答案

查看您的共享凭证文件

要使用凭证文件提供程序,只需按以下格式将您的访问 key 和 key 添加到 ~/.aws/credentials 文件中:

[default]
aws_access_key_id = AKID...
aws_secret_access_key = YOUR_SECRET_KEY

如果您还没有此文件/目录,请不要担心 - 只需为自己创建它们即可。

您可以在这里了解更多信息:https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SharedIniFileCredentials.html

关于node.js - 无法从任何提供商 Nodemailer aws 加载凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45599160/

相关文章:

amazon-web-services - 在 describe-vpcs 中按标签过滤的正确语法是什么?

linux - 在教程中无法启动 AWS Elastic Beanstalk

node.js - TCP还是UDP?视频流的制作延迟

Javascript - 并行调用两个异步函数并将两个结果传递给第三个函数

javascript - Node JS 使用 windows % 变量视为相对路径的绝对路径

bash - 将 Bash 命令与 AWS CLI 复制命令相结合

node.js - 我是否必须使用 ngrok 来公开 MERN 堆栈的前端和后端才能使 CRUD 操作正常工作?

amazon-web-services - AWS IAM : Unable to create additional Access Key

amazon-web-services - beego running on AWS 发行

r - 如何在AWS EC2实例上升级R版本?