简体   繁体   中英

Multiple DynamoDB tables with boto3: put item in table if person not exists in main table

DB schema

I have got 3 DynamoDB tables linked through GraphQL and AppSync. My api graph GetPerson return for skills a list of skills for that person scanning in Skills table. The same for Experience field.

Now I have to put new skills in skill table using a python script. My problem is: how can I put a new skill in skill table when the person doesn't exist in main table? So I need to put the person in main table first, then put skill in skills table, if person doesn't exist. Instead if person exists I think I only need to do table.put_item()

Two options. You could just use put_item() every time since it will create a new record if it doesn't exist or update the record if it does. The issue is that writes are a lot more expensive than reads.

More cost effective would be to check if the Person exists before putting the skills item.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM