oharaandrew314 / dynamodb-kotlin-module

Kotlin Module for the dynamodb-enhanced SDk
Apache License 2.0
26 stars 3 forks source link

empty Local secondary indices results in error when calling createTableWithIndices #6

Closed 1337jwilliams95 closed 2 years ago

1337jwilliams95 commented 2 years ago

When using createTableWithIndices to create a table with indices (global but not local) I get the following error Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tableInitializer': Invocation of init method failed; nested exception is software.amazon.awssdk.services.dynamodb.model.DynamoDbException: LSI list is empty/invalid (Service: DynamoDb, Status Code: 400, Request ID: 4c1beac5-c3cc-409e-89f9-778c1b2a27d0, Extended Request ID: null)

I believe this could be resolved like this below.

val builder = CreateTableEnhancedRequest.builder()
    globalIndices.takeIf { it.isNotEmpty() }?.apply { builder.globalSecondaryIndices(this) }
    localIndices.takeIf { it.isNotEmpty() }?.apply { builder.localSecondaryIndices(this) }
    val request = builder
        .build()

    createTable(request)

note: I wasn't able to reproduce my issue with your local tests

oharaandrew314 commented 2 years ago

Right, makes sense. I'll get this fixed unless you want to send a PR. I should also update local dynamo to match the behaviour of AWS, but that's another repo.

On Wed., Sep. 14, 2022, 11:17 a.m. John Williams, @.***> wrote:

When using createTableWithIndices to create a table with indices (global but not local) I get the following error Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tableInitializer': Invocation of init method failed; nested exception is software.amazon.awssdk.services.dynamodb.model.DynamoDbException: LSI list is empty/invalid (Service: DynamoDb, Status Code: 400, Request ID: 4c1beac5-c3cc-409e-89f9-778c1b2a27d0, Extended Request ID: null)

I believe this could be resolved like this below.

val builder = CreateTableEnhancedRequest.builder() globalIndices.takeIf { it.isNotEmpty() }?.apply { builder.globalSecondaryIndices(this) } localIndices.takeIf { it.isNotEmpty() }?.apply { builder.localSecondaryIndices(this) } val request = builder .build()

createTable(request)

note: I wasn't able to reproduce my issue with your local tests

— Reply to this email directly, view it on GitHub https://github.com/oharaandrew314/dynamodb-kotlin-module/issues/6, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG2JSB3W6SG5TLFAXOV7HTV6HUARANCNFSM6AAAAAAQMQVCYE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

1337jwilliams95 commented 2 years ago

Hey, thanks for the fast response! I tried creating a pr but it looks like I don't have the permissions. Those changes above worked for the repo test, and resolved my issue in my service!

oharaandrew314 commented 2 years ago

Turns out this problem was already noticed and a fix suggested in https://github.com/aws/aws-sdk-java-v2/issues/1771#issuecomment-1105109398. I've integrated the fix and addressed another shortcoming with projections when creating tables in real DynamoDB.

The fix is now available on Jitpack.