“ errorMessage”:“名称''未定义”

时间:2019-08-11 21:48:46

标签: python python-3.x amazon-web-services amazon-ec2 aws-lambda

我想使用保存在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",

1 个答案:

答案 0 :(得分:1)

在您的程序中,您没有定义变量participant_details,因此无法查找其值。您应该先定义该变量,然后再访问它。