我使用Visual Studio创建了一个AWS Lambda函数,使用.net core1.0
创建了C#我必须在对Lambda函数执行某些操作后发送电子邮件。 我的代码如下。取自AWS Doc
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using Amazon.Lambda.Core;
using System;
using System.Collections.Generic;
using Amazon.SimpleEmail;
using Amazon.SimpleEmail.Model;
using Amazon;
namespace MyProject
{
public class AddAlarms
{
private static AmazonDynamoDBClient client = new AmazonDynamoDBClient();
public string AddAlarmsHandler(GetUserAlerts input, ILambdaContext context)
{
var client = new AmazonSimpleEmailServiceClient(RegionEndpoint.USEast1);
List<string> toAddress = new List<string>();
toAddress.Add("ToEmail@domain.com");
var sendRequest = new SendEmailRequest
{
Source = "sourceEmail@domain.com",
Destination = new Destination
{
ToAddresses = toAddress
},
Message = new Message
{
Subject = new Content("Subject of email"),
Body = new Body
{
Html = new Content
{
Charset = "UTF-8",
Data = "Hello Email, HTML Body"
},
Text = new Content
{
Charset = "UTF-8",
Data = "Hello email, Text Body"
}
}
},
ConfigurationSetName = "ConfigSet"
};
string returnval = string.Empty;
try
{
Console.WriteLine("Sending email using Amazon SES...");
returnval += "Sending email using Amazon SES...";
var response = client.SendEmailAsync(sendRequest);
System.Threading.Thread.Sleep(5000);
returnval += ", Response Status - " + response.Status.ToString() + " - ";
Console.WriteLine("The email was sent successfully.");
returnval += "The email was sent successfully.....";
}
catch (Exception ex)
{
returnval += "The email was not sent.";
Console.WriteLine("The email was not sent.");
returnval += "Error message: " + ex.Message;
Console.WriteLine("Error message: " + ex.Message);
}
return returnval;
}
}
}
因此Lambda函数已成功创建,并在Lambda部分显示为AWS
因此,在测试此功能时,我会在发送后得到响应 - &#34; Faulted&#34; 并且收件人未收到电子邮件。
我已经验证了电子邮件TO和FROM都是对AWS SES的电子邮件验证。
我得到一个成功运行的Node.Js代码,还接收了我从link获取的电子邮件和node.js代码
我已经检查了ROLE并为Node.Js代码使用相同的角色并且工作正常,但对于C#lambda函数我得到了响应&#34; Faulted&#34;。
请帮助解决AWS Lambda中的此问题