我正在尝试使用amazon服务显示已标记'aws-lambda'的问题" rel ="tag"> aws-lambda ,以便将电子邮件发送给经过验证的收件人.
I'm trying to use the amazon-ses service on a aws-lambda in order to send an email to verified recipients.
我正在关注这很简单该教程显示了一个简单的 nodejs 函数的问题:
I'm following this simple tutorial which shows a simple nodejs function:
var aws = require('aws-sdk'); var ses = new aws.SES({region: 'us-east-1'}); exports.handler = (event, context, callback) => { var params = { Destination: { ToAddresses: ["recipientEmailAddress"] }, Message: { Body: { Text: { Data: "Test" } }, Subject: { Data: "Test Email" } }, Source: "sourceEmailAddress" }; ses.sendEmail(params, function (err, data) { callback(null, {err: err, data: data}); if (err) { console.log(err); context.fail(err); } else { console.log(data); context.succeed(event); } }); };以下政策是lambda角色的一部分:
The following policy is part of the lambda's role:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ses:SendEmail" ], "Resource": "*" } ] }出于某种原因,此lambda函数无法发送任何电子邮件,并且在该函数的CloudWatch Log组内未提供任何状态信息:
For some reason, this lambda function fails to send any emails and it doesn't provide any status information inside the function's CloudWatch Log group:
REPORT RequestId: XXX Duration: 534.59 ms Billed Duration: 600 ms Memory Size: 128 MB Max Memory Used: 117 MB
任何帮助将不胜感激.
编辑:我在沙盒模式中工作,并且 source 和收件人都是来自该地区的经过验证的电子邮件代码中提到的内容(它也反映在日志中-不会引发任何错误).
I work in sandbox-mode and both source and recipient are verified emails from the region mentioned in the code (It is also reflected in the logs - no errors being thrown).
我在SO中发现了以下问题-但对我的案子没有相关答案:
I Found the following questions in SO - but no relevant answer to my case:
在AWS Lambda函数中通过AWS SES发送电子邮件
AWS SES发送电子邮件lambda每次都不发送
SES电子邮件未发送
在发送邮件时出现python错误亚马逊ses与aws lambda
推荐答案我认为 context.succeed 已过时.您也可以使用 async/await :
I think context.succeed is deprecated. Also you can use async/await:
exports.handler = async (event, context) => { var params = { Destination: { ToAddresses: ["recipientEmailAddress"] }, Message: { Body: { Text: { Data: "Test" } }, Subject: { Data: "Test Email" } }, Source: "sourceEmailAddress" }; const data = ses.sendEmail(params).promise() return data };更多推荐
Lambda上的AWS SES
发布评论