Reputation: 886
I am trying to put (insert) a nested object in my DynamoDB table. The object I have constructed as per the boto3 documentation is:
itm = {
'uid': {
'S': 'some-unique-id-value'
},
'myArray': {
'L': [
{
'propOne': {
'S': 'this is value of prop 1'
},
'createdOn': {
'S': str(time.time())
},
'isActive': {
'BOOL': True
},
'propTwo': {
'S': 'this is value of prop 2'
},
'propThree': {
'S': 'this is value of prop 3'
}
}
]
}
}
And then I put the item using the dynamoDB client
:
dynamodb.put_item(TableName='myTableName', Item=itm)
But I am getting the exception:
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in Item.myArray.L[0]: "propOne", must be one of: S, N, B, SS, NS, BS, M, L, NULL, BOOL
Unknown parameter in Item.myArray.L[0]: "createdOn", must be one of: S, N, B, SS, NS, BS, M, L, NULL, BOOL
Unknown parameter in Item.myArray.L[0]: "isActive", must be one of: S, N, B, SS, NS, BS, M, L, NULL, BOOL
Unknown parameter in Item.myArray.L[0]: "propTwo", must be one of: S, N, B, SS, NS, BS, M, L, NULL, BOOL
Unknown parameter in Item.myArray.L[0]: "propThree", must be one of: S, N, B, SS, NS, BS, M, L, NULL, BOOL
I am following this documentation:
My goal is to store the item as shown in this JSON object:
{
"uid":"some-uid-val",
"myArray":[
{
"propOne":"item 1 prop 1 value",
"createdOn":"123456",
"isActive":true,
"propTwo":"item 1 prop 2 value",
"propThree":"item 1 prop 3 value"
},
{
"propOne":"item 2 prop 1 value",
"createdOn":"123456",
"isActive":true,
"propTwo":"item 2 prop 2 value",
"propThree":"item 2 prop 3 value"
}
]
}
What am I doing wrong?
Upvotes: 3
Views: 3702
Reputation: 13541
When you put an array,
'L': [
{'... recursive ...'},
],
it requires recursive of an item structure. Since you have dict type of list items, you have nest dict objects in the list. Then, your item should look like as follows:
itm = {
'uid': {
'S': 'some-unique-id-value'
},
'myArray': {
'L': [
'M': {
'propOne': {
'S': 'this is value of prop 1'
}
},
'M': {
'createdOn': {
'S': str(time.time())
}
},
'M': {
'isActive': {
'BOOL': True
}
},
'M': {
'propTwo': {
'S': 'this is value of prop 2'
}
},
'M': {
'propThree': {
'S': 'this is value of prop 3'
}
}
]
}
}
Upvotes: 4