Amazon SNS没有从Lambda触发器传递消息

时间:2019-06-03 18:46:38

标签: aws-lambda sms amazon-sns

我已经编写了以下lambda代码来发送短信。 SMS已创建,但SMS并未传送到设备。我猜它卡在了SNS队列或Lambda触发器队列中。

let AWS = require('aws-sdk');
const sns = new AWS.SNS();

exports.handler = async (event, callback) => {
  if (!event.request.session || event.request.session.length === 0) {
    const phone = event.request.userAttributes.phone_number
    const otp = Math.floor(100000 + Math.random() * 900000)
    const message = "OTP to login to Stable is "+otp

    sns.publish({
        Message: message,
        MessageAttributes: {
            'AWS.SNS.SMS.SMSType': {
                DataType: 'String',
                StringValue: 'Transactional'
            },
            'AWS.SNS.SMS.SenderID': {
                DataType: 'String',
                StringValue: 'sender'
            },
        },
        PhoneNumber: phone
    }).promise()
        .then(data => {
            console.log("Sent message to", phone);
            callback(null, data);
        })
        .catch(err => {
            console.log("Sending failed", err);
            callback(err);
        });


    event.response.privateChallengeParameters = {
      answer: otp
    };
    event.response.challengeMetadata = "CUSTOM_CHALLENGE";

  }
  console.log('raja');
  console.log(event);
  return event;
};

如何在设备中接收消息?是否缺少任何配置?

1 个答案:

答案 0 :(得分:0)

return event;行在SNS回调完成之前返回,@ kulls确认删除此行已解决问题