每当我尝试从Lambda(使用Java)向SES发送电子邮件时,它都会失败 - 连接超时。AWS:通过SES从Lambda发送电子邮件
我测试了与Lambda函数相同的VPC中的EC2实例的完全相同的代码,并且它从那里工作(它们具有相同的角色分配)。我也试着运行Lambda函数,但它不在VPC中(尽管它需要在一个中),而且这也不起作用。
这里的代码
SendEmailRequest request = new SendEmailRequest().withSource(from)
.withDestination(destination)
.withMessage(message);
try {
System.out.println("Attempting to send an email through Amazon SES by using the AWS SDK for Java...");
if (client == null) {
client = new AmazonSimpleEmailServiceClient();
client.setRegion(Region.getRegion(Regions.EU_WEST_1));
}
client.sendEmail(request); // this is where the exception is thrown
System.out.println("Email sent!");
} catch (Exception ex) {
ex.printStackTrace();
System.err.println(ex.getMessage());
}
}
错误消息的相关位说,它无法连接(到email.eu西-1 ...)由于超时。
任何想法,为什么它不是从Lambda工作?
如果您将Lambda函数放入VPC中,那么它将无法访问VPC之外的任何内容(包括AWS API),除非您还为您的VPC添加了NAT网关。 –
@MarkB我在问题中注意到我在VPC之外尝试了它,并且它没有以完全相同的方式工作。 –
如果它仍然没有进入VPC超时,那么您确定它是连接到SES的超时,而不是Lambda函数耗尽分配时间吗?可能显示实际的错误信息?代码是否在本地运行? –