I am querying/scanning the DynamoDB table and getting the expected response. The response contains data type as well in dict Key :{'S':'String'}
, how can I get a response just in Key : Value
format i.e., 'Key:'String'
Here is API code:
client = boto3.client('dynamodb')
scanresponse = client.scan(TableName=os.environ['dynamodb_id'])
print(scanresponse)
Current Response:
{"items": [{"account_name": {"S": "some_account"}, "cloud_platform": {"S": "AWS"}, "created_on": {"S": "2023-09-15T05:24:05"}}]
I have tried to use a higher-layer API as below but it has limitations on a number of items in response. I expect 3000-10,000 items in response.
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('name')
I want to get a response in below format:
{"items": [{"account_name": "some_account", "cloud_platform": "AWS", "created_on": "2023-09-15T05:24:05"}]
2
Answers
You will want to use a python equivalen of unmarshall/marshall utilities found in
@aws-sdk/util-dynamodb
A 3rd party Python library exists here
Both the higher level client and lower level client have the same limit on number of items returned, they can read up to 1MB per page.
You can continue to use the low level client and just deserialize the results. This blog post highlights everything you need to know:
https://aws.amazon.com/blogs/database/exploring-amazon-dynamodb-sdk-clients/
As for the number of items returned, if you require more you can just implement pagination:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.Pagination