- Newest
- Most votes
- Most comments
In your code, you are using a mixture of data types with the low level client, which supports DynamoDB-JSON only.
Have a read of this blog post: https://aws.amazon.com/blogs/database/exploring-amazon-dynamodb-sdk-clients/
Using low level client would be:
{'mybool': {'BOOL': False}}
dynamo = boto3.client('dynamodb') #dynamodb not dynamo
try:
dynamo.put_item(
TableName='MyTable',
Item={
"dob": {"N": "1985"},
"name": {"S": title},
"info": {
"M": {
"email": {"S": "abc@xyz.com"},
"phone": {"S": "12093849393"}
}
},
"paid": {"BOOL": False}
}
)
except ClientError as err:
logger.error(err)
High level client:
'mybool' : False
dynamo = boto3.client('dynamodb') #dynamodb not dynamo
table = dynamo.Table('MyTable')
try:
dynamo.put_item(
Item={
"dob": 1985,
"name": "title",
"info": {
"email": "abc@xyz.com",
"phone": "12093849393"
},
"paid": False
}
)
except ClientError as err:
logger.error(err)
Hello.
I have checked the following documents.
I confirmed that I can register it with DynamoDB by modifying the code as below in my environment.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/put_item.html
dynamo.put_item(
TableName='test', # Please specify a TableName
Item={
"dob": {"N": "1985"},
"name": {"S": title},
"info": {
"M": {
"email": {"S": "abc@xyz.com"},
"phone": {"S": "12093849393"}
}
},
"paid": {"BOOL": False}
}
)
In your code, you should not use the dictionary with "BOOL" as the key for a boolean attribute. The "BOOL" key is not required when specifying boolean values in DynamoDB.
Here's how you can update the code to create/update an item with a boolean attribute in Python:
dynamo = boto3.client('dynamo')
try:
dynamo.put_item(
Item={
"dob": 1985,
"name": title,
"info": {"email": abc@xyz.com, "phone": "12093849393"},
"paid" : False
}
)
except ClientError as err:
logger.error(err)
Relevant content
- asked 3 months ago
- Accepted Answerasked a year ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated a month ago
@Riku - False specified in the book value , is python right ? How does dynamo db deserialize it ?
I didn't have an environment to run boto3 in my local environment, so I executed it with Lambda.