【发布时间】:2021-06-23 17:45:52
【问题描述】:
我在使用 client.put_item 方法将字典列表放入我的表时遇到问题。字典格式为:{"name": "beef", "price":5.23}。此类列表的一个示例是:[{"name": "chicken", "price":6.23}, {"name": "beef", "price":5.34}, {"name": "pork", "price":8.48}],其中列表大小可能会有所不同。到目前为止我有
def create_order(order_id, cart, total):
dynamodb = boto3.client('dynamodb')
table = 'Orders'
response = dynamodb.put_item(TableName=table,
Item={
'order_id': {"S":order_id},
'order_total': {"N":str(total)},
'cart':{"L":cart}
}
)
return response
它适用于 order_id 和 order_total,但我不知道如何格式化购物车。
【问题讨论】:
-
你给的例子列表是
cart的例子吗?你遇到了什么错误?
标签: python aws-lambda amazon-dynamodb boto3