如何通过Lambda将Csv插入Dynamo DB

时间:2020-07-31 16:23:29

标签: python aws-lambda amazon-dynamodb

Csv低于

"id (S)","Control (S)","Status (S)","level (S)","lifecycle (S)","name (S)","childId (S)","childName (S)","seg (S)"
"1","Public","Active","0","Ong","Commercial","","",""
"10","Public","Active","1","Ong","Analog ","5","On-Going Care",""
"11","Public","Active","","0","Ong","RWESS","","",""

代码在下面

import boto3
import csv
def lambda_handler(event, context):
    region='us-east-1'
    recList=[]
    try:            
        s3=boto3.client('s3')            
        dyndb = boto3.client('dynamodb', region_name=region)
        confile= s3.get_object(Bucket='business', Key='business.csv')
        recList = confile['Body'].read().decode("utf-8").split('\n')
        firstrecord=True
        csv_reader = csv.reader(recList, delimiter=',', quotechar="'", quoting=csv.QUOTE_ALL, skipinitialspace=True)
        for row in csv_reader:
            print (row)
            if (firstrecord):
                firstrecord=False
                continue
            id = row[0]
            response = dyndb.put_item(
                TableName='business',
                Item={
                'id' : {'S': id (S)}
                }
            )
        print('Put succeeded:')
    except Exception as e:
        print (str(e))

我需要将所有内容都插入dynamodb中。我已经使用id字符串创建了业务表。

仅在上面的代码中id正在插入rest参数未插入,并且id在表中带有双引号

0 个答案:

没有答案