我想读取DynamoDb表的所有项目。我正在使用table.scan()函数。它给了我回应。但是,输出是随意排列的。 我应该得到这样的输出-
{
"Items": [
{
"Name": "ABC",
"Location": "sdkjc",
"id": "abc"
},
{
"Name": "DEF",
"Location": "jfyef",
"id": "def"
}
]
}
但是我得到-
{
"Items": [
{
"Name": "ABC",
},
{
"Location": "sdkjc",
"id": "abc"
},
{
"Name": "DEF",
"Location": "jfyef",
},
{
"id": "def"
}
]
}
代码-
import boto3
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table(event['tableName'])
response = table.scan()
print (response)
输出中没有图案。可能是什么问题?
答案 0 :(得分:0)
try something like
def read():
dynamodb = boto3.resource('dynamodb', region_name='us-west-2')
table = dynamodb.Table("test")
items = table.scan()['Items']
for item in items:
print (item)