Search code examples
amazon-dynamodbboto3

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()


Solution

  • 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.