【发布时间】:2019-12-18 14:24:59
【问题描述】:
我想使用 Python 在 Lambda 中创建一个保存在 CSV 文件中的报告。所以你会找到函数的代码:
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",
【问题讨论】:
-
for detail in participant_details:什么是参与者详细信息?你在哪里定义它? -
@sertsedat 所以应该是响应而不是参与者详细信息?
标签: python python-3.x amazon-web-services amazon-ec2 aws-lambda