为什么我不能从Lambda Function发送SendGrid电子邮件?

时间:2019-03-05 17:55:09

标签: node.js amazon-web-services aws-lambda sendgrid

我正在努力理解为什么我的Lambda无法发送此Sendgrid消息。

当我调用Lambda时,我会依次获得console.log 1,2,3以及Sendgrid调用中的null。永远不会调用Sendgrid Promise回调。知道为什么吗?

"use strict";

const sendgrid = require('@sendgrid/mail');

sendgrid.setApiKey('xxxxxxxxx');

module.exports.scan = async (event, context, onComplete) => {
  console.log('1');

  await (() => {
    console.log('2');
    sendgrid.send({
      to: 'xxxxxxx',
      from: 'xxxxxxxxx',
      subject: 'Sending with SendGrid is Fun',
      text: 'and easy to do anywhere, even with Node.js',
      html: '<strong>and easy to do anywhere, even with Node.js</strong>',
    })
    .then(() => {
      console.log('cool');
      onComplete(null, "successfully updated form next_scheduled")
    })
    .catch(error => {
      console.log('error');

      //Log friendly error
      console.error(error.toString());

      //Extract error msg
      const {message, code, response} = error;

      //Extract response msg
      const {headers, body} = response;

      onComplete(error, "failed to updated form next_scheduled")
    });
  })();

  console.log('3');
};

0 个答案:

没有答案