我们正在尝试创建一个 AWS Lambda 函数来创建一封带有 HTML 正文的电子邮件,以提醒团队有关更改的记录。
为了实现这一目标,我们使用 Python 创建了一个 Lambda 函数,该函数从事件响应中捕获变量并传递到 HTML。我下面的代码在从 HTML 到 python 的变量方面存在问题。你能帮我解决它吗?
由于发送的电子邮件只是 HTML 中提到的字符串。一般来说,我应该获取分配给它的变量。
import boto3
import json
from datetime import datetime
import smtplib
import email.utils
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def lambda_handler(event, context):
#print(event)
RecordInfo = event['Records']
RecordDetails = RecordInfo[0]
EventName = RecordDetails['eventName']
Dyna = RecordDetails['dynamodb']
Modtime = Dyna['ApproximateCreationDateTime']
ModifiedTime=datetime.fromtimestamp(Modtime).strftime("%B %d, %Y %I:%M:%S")
if (EventName == 'MODIFY'):
OldData = Dyna['OldImage']
OldAppKey=OldData['Application']
OldApp=OldAppKey['S']
OldAppServerKey=OldData['App_Server']
OldAppServer=OldAppServerKey['S']
OldAppUserKey=OldData['App_User']
OldAppUser=OldAppUserKey['S']
OldAppIPKey=OldData['App_IP']
OldAppIP=OldAppIPKey['S']
OldAppPwdKey=OldData['App_Pwd']
OldAppPwd=OldAppPwdKey['S']
OldAppPortKey=OldData['App_Port']
OldAppPort=OldAppPortKey['S']
#If Eventname is 'Modify' then above inserted value of Sub will be overridden
# The subject line of the email.
SUBJECT = "Table Name:DBTest - Updated on " + ModifiedTime
Message1 = Message1 + "\nOld Record Details:\n" + "Application:" + OldApp + "\tApp_IP:" + OldAppIP + "\tApp_User:" + OldAppUser + "\tApp_Pwd:" + OldAppPwd + "\tApp_Port:" + OldAppPort
茅侃侃
相关分类