代码如下
import json
from decimal import Decimal
from pprint import pprint
import boto3
def update_movie(title, year, rating=None, plot=None, actors=None, dynamodb=None):
if not dynamodb:
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Movies')
response = table.update_item(
Key={
'year': year,
'title': title
},
UpdateExpression="set info.rating=:r, info.plot=:p, info.actors=:a",
ExpressionAttributeValues={
':r': Decimal(rating),
':p': plot,
':a': actors
},
ReturnValues="UPDATED_NEW"
)
return response
def lambda_handler(event, context):
update_response = update_movie(
"Rush", 2013, 8.3, "Car show",
["Daniel", "Chris", "Olivia"])
print("Update movie succeeded:")
pprint(update_response, sort_dicts=False)
在 dynamodb 中更新密钥时出现以下错误
"errorMessage": "[<class 'decimal.Inexact'>, <class 'decimal.Rounded'>]",
"errorType": "Inexact",
如果我更改8.3为8我的代码工作正常
update_response = update_movie(
"Rush", 2013, 8.3, "Car show",
["Daniel", "Chris", "Olivia"])
print("Update movie succeeded:")```
慕丝7291255
慕田峪9158850
潇潇雨雨
相关分类