【发布时间】:2020-06-25 03:18:18
【问题描述】:
我有一个带有嵌套 for 循环的 python lambda
def lambda_handler(event, context):
acc_ids = json.loads(os.environ.get('ACC_ID'))
with open('/tmp/newcsv.csv', mode='w', newline='') as csv_file:
fieldnames = ['DomainName', 'Subject', 'Status', 'RenewalEligibility', 'InUseBy']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
for acc_id in acc_ids:
try:
//do something
for region in regions_to_scan:
try:
// do something
if something:
for x in list:
// get values for row
writer.writerow('write rows here')
except Exception as e:
print(e)
continue
except Exception as e:
print(e)
continue
s3 = boto3.client('s3')
response = s3.upload_file('/tmp/newcsv.csv', 'my-bucket', 'newcsv.csv')
这不是在 S3 中上传文件,从其他对话中我确保文件的上传是在编写上下文完成之后。有人可以评估我的脚本吗?
【问题讨论】:
-
您是否查看了 CloudWatch Logs 以找到任何错误消息?我建议您开始上传工作,然后担心文件内容。因此,只需尝试
download_file()获取一些本地内容,然后尝试upload_file()该文件以确认上传工作正常。如果它正在工作,那么问题可能出在创建 CSV 文件的代码上。
标签: python csv amazon-s3 nested-loops