ocind
ocind

Reputation: 159

Is it possible to provide custom logic for Secondary Index key creation?

For my secondary index, I would like to have a key column which is a semicolon separated data of 2 columns in the base table.

Is it possible to create a custom logic to generate such value for the key column in secondary index?

Upvotes: 0

Views: 34

Answers (1)

thomasmichaelwallace
thomasmichaelwallace

Reputation: 8474

Unfortunately you can only use another key, verbatim- no transformations or custom logic.

If this is essential for you, however, you can enable DynamoDB streams on your table, and use them to trigger a lambda. The lambda could either:

  • Adds/update a column with your custom logic value in your table that you'd use for your GSI (just be careful to check the UPDATE document so you don't get stuck in an infinite loop!)
  • Populate/update a second table with the custom logic key and any attributes you want.

I would probably lean towards the former, because then removal and synchronization of data is still DynamoDB's responsibility.

n.b. if you only need your key to be the two combined values, you could just use one as a partition and the other as a sort for your GSI.

Upvotes: 1

Related Questions