我創建了一個lambda函數,當文件上傳到s3存儲桶時發送電子郵件,但是現在我想要將與該文件相關的所有信息作爲名稱,大小,日期和上傳時間,以及它可能來自何處。 我在aws控制檯上擁有所有這些infortmation,但希望將它放在電子郵件正文中。獲取關於上傳到S3的文件的信息
我正在使用無服務器框架。 v 1.22.0
這裏是我的代碼
import json
import boto3
import botocore
import logging
import sys
import os
import traceback
from botocore.exceptions import ClientError
from pprint import pprint
from time import strftime, gmtime
email_from = '********@*****.com'
email_to = '********@*****.com'
email_subject = 'new event on s3 '
email_body = 'a new file is uploaded'
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
from botocore.exceptions import ClientError
def sthree(event, context):
"""Send email whenever a file is uploaded to S3"""
body = {}
status_code = 200
email_body = str(context)
try:
s3 = boto3.client('s3')
ses = boto3.client('ses')
ses.send_email(Source = email_from,
Destination = {'ToAddresses': [email_to,],},
Message = {'Subject': {'Data': email_subject}, 'Body':{'Text' : {'Data': email_body}}}
)
except Exception as e:
print(traceback.format_exc())
status_code = 500
body["message"] = json.dumps(e)
response = {
"statusCode": 200,
"body": json.dumps(body)
}
return response
非常感謝你,這是非常有幫助 – ner