[英]An error occurred (ValidationException) when calling the PutItem operation: One or more parameter values were invalid: Missing the key CreatedAt
[英]Error occurred (ValidationException) when calling the PutItem operation: while updating DynamoDB from CSV file
下面是csv
1,'Chaks, Raj','$300,000', False
2,'Chen, Joe','$250,000', False
3,'Kumar, Harry','$240,000', True
下面是代碼
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='csvfolder3', Key='employee.csv')
recList = confile['Body'].read().decode('utf-8').split('\n')
firstrecord=True
csv_reader = csv.reader(recList, delimiter=',', quotechar='"')
for row in csv_reader:
if (firstrecord):
firstrecord=False
continue
empid = row[0]
name = row[1].replace(',','').replace('$','') if row[1] else '-'
salary = row[2].replace(',','').replace('$','') if row[2] else 0
response = dyndb.put_item(
TableName='emplist',
Item={
'empid' : {'N':str(empid)},
'name': {'S':name},
'salary': {'N':str(salary)},
'parttime': {'BOOL':False},
}
)
print('Put succeeded:')
except Exception as e:
print (str(e))
下面是拋出的錯誤:
需要類似 object 的字節,而不是“str”
從 csv 更新到 DynamoDB
錯誤:
調用 PutItem 操作時發生錯誤 (ValidationException):無法將參數轉換為數值:Joe
問題在於你的引號。
該文件包含:
1,'Chaks, Raj','$300,000', False
2,'Chen, Joe','$250,000', False
3,'Kumar, Harry','$240,000', True
但是,您告訴csv_reader
引號是雙引號:
csv_reader = csv.reader(recList, delimiter=',', quotechar='"')
因此,只需將其更改為:
csv_reader = csv.reader(recList, delimiter=',', quotechar="'")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.