Ten Examples of Getting Data from DynamoDB with Python and Boto3
https://www.fernandomc.com/posts/ten-examples-of-getting-data-from-dynamodb-with-python-and-boto3/

Please find below a reference to REST API documentation
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/Welcome.html

Key Condition Expression
https://docs.amazonaws.cn/en_us/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
a = b — true if the attribute a is equal to the value b
a < b — true if a is less than b
a <= b — true if a is less than or equal to b
a > b — true if a is greater than b
a >= b — true if a is greater than or equal to b
a BETWEEN b AND c — true if a is greater than or equal to b, and less than or equal to c.
begins_with (a, substr)— true if the value of attribute a begins with a particular substring.

condition-expression ::=
      operand comparator operand
    | operand BETWEEN operand AND operand
    | operand IN ( operand (',' operand (, ...) ))
    | function
    | condition AND condition
    | condition OR condition
    | NOT condition
    | ( condition )

comparator ::=
    =
    | <>
    | <
    | <=
    | >
    | >=

function ::=
    attribute_exists (path)
    | attribute_not_exists (path)
    | attribute_type (path, type)
    | begins_with (path, substr)
    | contains (path, operand)
    | size (path)


Example Hashkey only
response = tbl.query(
    KeyConditionExpression='subscriptionId = :exp_subscriptionId',
    ExpressionAttributeValues={
        ":exp_subscriptionId": "233c1209-9b90-4866-b10a-a21278371ccc"
    },
)


Example Hashkey + Range Key
response = tbl.query(
    KeyConditionExpression='subscriptionId = :exp_subscriptionId',
    ExpressionAttributeValues={
        ":exp_subscriptionId": "233c1209-9b90-4866-b10a-a21278371ccc",
        ":exp_workflowName": "APP_ASANA"
    },
)


Example Index Key
response = tbl.query(
    IndexName='subscriptionId-index',
    KeyConditionExpression='subscriptionId = :exp_subscriptionId',
    ExpressionAttributeValues={
        ":exp_subscriptionId": "233c1209-9b90-4866-b10a-a21278371ccc"
    },
)


Example with Filter and Index
response = tbl.query(
    IndexName='subscriptionId-index',
    KeyConditionExpression='subscriptionId = :exp_subscriptionId',
    FilterExpression='begins_with(workflowName, :exp_workflowName)',
    ExpressionAttributeValues={
        ":exp_subscriptionId": "233c1209-9b90-4866-b10a-a21278371ccc",
        ":exp_workflowName": "APP_ASANA"
    },
)


Related Articles
Mapper
Was this article helpful?
Cancel
Thank you!