Reputation: 1065
I want to read all items of a DynamoDb table. I am using the table.scan() function. It is giving me the response. But, the output is arranged in a haphazard way. I am supposed to get output like this -
{
"Items": [
{
"Name": "ABC",
"Location": "sdkjc",
"id": "abc"
},
{
"Name": "DEF",
"Location": "jfyef",
"id": "def"
}
]
}
But I am getting -
{
"Items": [
{
"Name": "ABC",
},
{
"Location": "sdkjc",
"id": "abc"
},
{
"Name": "DEF",
"Location": "jfyef",
},
{
"id": "def"
}
]
}
Code -
import boto3
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table(event['tableName'])
response = table.scan()
print (response)
There is no pattern in the output. What can be the issue?
Upvotes: 6
Views: 5060
Reputation: 69
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)
Upvotes: 2