我想使用保存在CSV文件中的Python在Lambda中创建报告。因此,您将找到该函数的代码:
import boto3
import re
import csv
def lambda_handler(event,context):
client = boto3.client('ce')
response = client.get_cost_and_usage(
TimePeriod={
'Start': "2019-02-01",
'End': "2019-08-01"
},
Granularity='MONTHLY',
Metrics=['BlendedCost'],
GroupBy=[
{
'Type': 'TAG',
'Key': 'Project'
},
]
)
temp_csv_file = csv.writer(open("/tmp/csv_file.csv", "w+"))
# writing the column names
temp_csv_file.writerow(["Account Name", "Month", "Cost"])
# writing rows in to the CSV file
for detail in participant_details:
temp_csv_file.writerow([response['account_name'],
response['month'],
response['cost']
])
client = boto3.client('s3')
client.upload_file('/tmp/csv_file.csv', BUCKET_NAME,'final_report.csv')
如何解决以下错误?
"errorMessage": "name 'participant_details' is not defined",
答案 0 :(得分:1)
在您的程序中,您没有定义变量participant_details
,因此无法查找其值。您应该先定义该变量,然后再访问它。