Reputation: 27
I am new to coding. I appreciate the help. I already create a DynamoDB table, API Gateway, child resource, child method(POST), integration type: AWS service proxy. I also created an IAM role to allow access to DynamoDB putitem. I tried to add something to the table with postman and it worked well. However, now I want to add an item to the table with boto3 and I'm finding it hard to identify the method that I should be using.
Upvotes: 0
Views: 108
Reputation: 5648
dydbsr = boto3.resource('dynamodb')
dbtable = 'myTable'
table = dydbsr.Table(dbtable)
If you have a partition key only:
partion key is: mypartitionkey
json_dictionary = {"mypartitionkey": "myvalue"}
table.put_item(Item=json_dictionary)
If you have a partition key and sort key. If sort key is defined it MUST be included
partion key is: mypartitionkey
sort key is: mysortkey
json_dictionary = {"mypartitionkey": "myvalue", "mysortkey": "myothervalue"}
table.put_item(Item=json_dictionary)
After adding partition and sort keys, then your attributes are just key:value pairs in the same json dictionary
Upvotes: 0