【发布时间】:2019-08-20 18:16:58
【问题描述】:
我正在使用 AWS Lambda、Python 3.7 和 SendGrid API 并想发送电子邮件但收到错误:
"Unable to import module 'lambda_function': No module named 'sendgrid'"
有没有办法解决这个问题?我可以看到在一些类似的问题中,模块会从某个地方导入,但无法从哪里解决。
我的 lambda 代码只是来自 SendGrid 网站的示例代码,其中的值已更新为我要使用的值:
import json
import sendgrid
import os
from sendgrid.helpers.mail import *
def lambda_handler(event, context):
sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
from_email = Email("test@example.com")
to_email = Email("****")
subject = "Sending with SendGrid is Fun"
content = Content("text/plain", "and easy to do anywhere, even with Python")
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
print(response.status_code)
print(response.body)
print(response.headers)
谢谢
【问题讨论】:
标签: python-3.x aws-lambda sendgrid sendgrid-api-v3