Reputation: 11
I'm facing an issue with dynamodb, I'm new to this and it seems so hard to understand... while it seems "easy" with SQL
I hope you will be able to help me understand what I'm missing :)
I have some information, like this:
Role
- identifier (hash)
- label
User
- identifier (hash)
- label
- roleIdentifierList (each role is a different user... I don't like this, but that's the only way to get a range here I guess)
Item
- identifier (hash)
- roleIdentifier (global secondary index)
- label
How, with an "user identifier" and an "item identifier" could I be sure that this user has the correct role?
I'm afraid my tables aren't well formed but documentation seems a little bit light.
Thanks!
I'm currently doing a scan on User
to get all roles of user with identifier
Then, I've try (but without success because we can't use "contains" with getItem
) to retrieve the item with the correct id and at the same time check if there is the correct role.
Is this correct to do a getItem
and then in another logic rule (not related with dynamodb), check if the role is present?
Upvotes: 0
Views: 98
Reputation: 19883
Without going into your datamodel and access patterns, the simple answer is for you to use Query
API, which will allow you to provide a FilterExpression
where you can use contains
.
aws dynamodb query \
--table-name my-table-name \
--key-condition-expression "#pk = :pk" \
--filter-expression "contains(#y, :y)" \
--expression-attribute-values '{ ":y": { "S": "some identiier" }, ":pk": { "S": "abc" }}' \
--expression-attribute-names '{"#y":"some attribute name", "#pk":"identifier"}'
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
Upvotes: 1