0

this is a trivial question but I didn't found the answer on how to get the primary from a dynamoDB table in AWS. (I know we can from the dynamodb object but I would like to keep it directly from dynamodb.Table.

Problem: AttributeError: 'dynamodb.Table' object has no attribute 'primary_key'

Solution: Something like my_table.get_primary_key() ?

1 Answer 1

1
import inspect
print(inspect.getmembers(table, lambda a: not (inspect.isroutine(a))))

Result:

[....('attribute_definitions', [{'AttributeName': 'mail', 'AttributeType': 'S'}]), ...]

Answer::

def get_primary_key(table):
    return table.attribute_definitions[0]["'AttributeName"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.