I am trying a simple operation on my DynamoDB table. The schema is very simple
(Hash Key) SummaryId : String (Sort Key) Status : String
def put_item(dynamo_table, summary_id, status):
return dynamo_table.put_item(
Item={
'SummaryId': summary_id,
'Status': status
},
ReturnValues="ALL_OLD"
)
def update_item(dynamo_table, summary_id, status):
response = dynamo_table.update_item(
Key={'SummaryId': summary_id},
AttributeUpdates={
'Status': status,
},
ReturnValues="UPDATED_OLD"
)
return response
def initialize_dynamodb_table():
dynamodb = boto3.Session(profile_name=PROFILE_NAME,
region_name=REGION_NAME) \
.resource('dynamodb')
return dynamodb.Table(TABLE_NAME)
def main():
dynamodb_table = initialize_dynamodb_table()
# Update the above item
response = put_item(dynamodb_table, "Id1::Id2::Id4", "IN_PROGRESS")
pprint(response)
response = update_item(dynamodb_table, "Id1::Id2::Id4", "COMPLETE")
pprint(response)
if __name__ == '__main__':
main()
The item with PK "Id1::Id2::Id4" doesn't exist. So the put_item() is expected to add this item. My intention with the update_item() api is that it will change the item status from "IN_PROGRESS" to "COMPLETE". But instead the update_item() API creates a new item in the table with PK "Id1::Id2::Id4" and RK "COMPLETE"
How do I achieve the expected behavior? Thanks in advance!