paws-r / paws

Paws, a package for Amazon Web Services in R
https://www.paws-r-sdk.com
Other
314 stars 37 forks source link

error when using update_table with GlobalSecondaryIndexUpdates #655

Closed ricds closed 1 year ago

ricds commented 1 year ago

Hello, I do create_table with globalsecondaryindex, then i want to update_table to reduce ProvisionedThroughput for the index (not the table), and I get this error below. I previously had 1.xx version of aws cli, but now i updated to "aws-cli/2.13.11 Python/3.11.4 Linux/5.4.0-1103-aws exe/x86_64.ubuntu.18 prompt/off" and it is still not working.

Am I doing something wrong or is this a bug with the package? Thanks for your time.

error: ## Error in populate_fn(input, interface) : invalid name: IndexName

code:

# create table with index
con$create_table(
  AttributeDefinitions = list(
    list(
      AttributeName = "id",
      AttributeType = "N"
    ),
    list(
      AttributeName = "tile",
      AttributeType = "S"
    ),
    list(
      AttributeName = "tstatus",
      AttributeType = "N"
    )
  ),
  KeySchema = list(
    list(
      AttributeName = "id",
      KeyType = "HASH"
    ),
    list(
      AttributeName = "tile",
      KeyType = "RANGE"
    )
  ),
  ProvisionedThroughput = list(
    ReadCapacityUnits = 5,
    WriteCapacityUnits = 200
  ),
  GlobalSecondaryIndexes = list(
    Create = list(
      IndexName = "tstatusIndex",
      KeySchema = list(
        list(AttributeName = "tstatus", KeyType = "HASH") #Partition key
        ,list(AttributeName = "id", KeyType = "RANGE") #Sort key
      ),
      Projection = list(
        ProjectionType = "ALL"
      ),
      ProvisionedThroughput = list(                                # Only specified if using provisioned mode
        ReadCapacityUnits = 5,
        WriteCapacityUnits = 10
      )
    )
  ),
  TableName = "test"
)

# update table to reduce throughput
con$update_table(
  TableName = "test",
  ProvisionedThroughput = list(
    ReadCapacityUnits = 5,
    WriteCapacityUnits = 2
  ),
  GlobalSecondaryIndexUpdates = list(
    Update = list(
      IndexName = "tstatusIndex",
      ProvisionedThroughput = list(
        ReadCapacityUnits = 5,
        WriteCapacityUnits = 2
      )
    )
  )
)
DyfanJones commented 1 year ago

Hi @ricds What paws service are you using? I am not sure what con is.

ricds commented 1 year ago

my bad, it is dynamodb, i tested the aws cli directly and it worked, so i'd assume it is somethign in the code preventing it to run

DyfanJones commented 1 year ago

It looks like you have got GlobalSecondaryIndexUpdates in the wrong format. From looking at the documentation: https://www.paws-r-sdk.com/docs/dynamodb_update_table/#request-syntax

The format for each parameter is as follows:

svc$update_table(
  AttributeDefinitions = list(
    list(
      AttributeName = "string",
      AttributeType = "S"|"N"|"B"
    )
  ),
  TableName = "string",
  BillingMode = "PROVISIONED"|"PAY_PER_REQUEST",
  ProvisionedThroughput = list(
    ReadCapacityUnits = 123,
    WriteCapacityUnits = 123
  ),
  GlobalSecondaryIndexUpdates = list(
    list(
      Update = list(
        IndexName = "string",
        ProvisionedThroughput = list(
          ReadCapacityUnits = 123,
          WriteCapacityUnits = 123
        )
      ),
      Create = list(
        IndexName = "string",
        KeySchema = list(
          list(
            AttributeName = "string",
            KeyType = "HASH"|"RANGE"
          )
        ),
        Projection = list(
          ProjectionType = "ALL"|"KEYS_ONLY"|"INCLUDE",
          NonKeyAttributes = list(
            "string"
          )
        ),
        ProvisionedThroughput = list(
          ReadCapacityUnits = 123,
          WriteCapacityUnits = 123
        )
      ),
      Delete = list(
        IndexName = "string"
      )
    )
  ),
  StreamSpecification = list(
    StreamEnabled = TRUE|FALSE,
    StreamViewType = "NEW_IMAGE"|"OLD_IMAGE"|"NEW_AND_OLD_IMAGES"|"KEYS_ONLY"
  ),
  SSESpecification = list(
    Enabled = TRUE|FALSE,
    SSEType = "AES256"|"KMS",
    KMSMasterKeyId = "string"
  ),
  ReplicaUpdates = list(
    list(
      Create = list(
        RegionName = "string",
        KMSMasterKeyId = "string",
        ProvisionedThroughputOverride = list(
          ReadCapacityUnits = 123
        ),
        GlobalSecondaryIndexes = list(
          list(
            IndexName = "string",
            ProvisionedThroughputOverride = list(
              ReadCapacityUnits = 123
            )
          )
        ),
        TableClassOverride = "STANDARD"|"STANDARD_INFREQUENT_ACCESS"
      ),
      Update = list(
        RegionName = "string",
        KMSMasterKeyId = "string",
        ProvisionedThroughputOverride = list(
          ReadCapacityUnits = 123
        ),
        GlobalSecondaryIndexes = list(
          list(
            IndexName = "string",
            ProvisionedThroughputOverride = list(
              ReadCapacityUnits = 123
            )
          )
        ),
        TableClassOverride = "STANDARD"|"STANDARD_INFREQUENT_ACCESS"
      ),
      Delete = list(
        RegionName = "string"
      )
    )
  ),
  TableClass = "STANDARD"|"STANDARD_INFREQUENT_ACCESS",
  DeletionProtectionEnabled = TRUE|FALSE
)

So your format should be:

con$update_table(
  TableName = "test",
  ProvisionedThroughput = list(
    ReadCapacityUnits = 5,
    WriteCapacityUnits = 2
  ),
  GlobalSecondaryIndexUpdates = list(
    list(
      Update = list(
        IndexName = "tstatusIndex",
        ProvisionedThroughput = list(
          ReadCapacityUnits = 5,
          WriteCapacityUnits = 2
        )
      )
    )
  )
)

Let me know if this works out for you :)

ricds commented 1 year ago

It looks like you have got GlobalSecondaryIndexUpdates in the wrong format. From looking at the documentation: https://www.paws-r-sdk.com/docs/dynamodb_update_table/#request-syntax

The format for each parameter is as follows:

svc$update_table(
  AttributeDefinitions = list(
    list(
      AttributeName = "string",
      AttributeType = "S"|"N"|"B"
    )
  ),
  TableName = "string",
  BillingMode = "PROVISIONED"|"PAY_PER_REQUEST",
  ProvisionedThroughput = list(
    ReadCapacityUnits = 123,
    WriteCapacityUnits = 123
  ),
  GlobalSecondaryIndexUpdates = list(
    list(
      Update = list(
        IndexName = "string",
        ProvisionedThroughput = list(
          ReadCapacityUnits = 123,
          WriteCapacityUnits = 123
        )
      ),
      Create = list(
        IndexName = "string",
        KeySchema = list(
          list(
            AttributeName = "string",
            KeyType = "HASH"|"RANGE"
          )
        ),
        Projection = list(
          ProjectionType = "ALL"|"KEYS_ONLY"|"INCLUDE",
          NonKeyAttributes = list(
            "string"
          )
        ),
        ProvisionedThroughput = list(
          ReadCapacityUnits = 123,
          WriteCapacityUnits = 123
        )
      ),
      Delete = list(
        IndexName = "string"
      )
    )
  ),
  StreamSpecification = list(
    StreamEnabled = TRUE|FALSE,
    StreamViewType = "NEW_IMAGE"|"OLD_IMAGE"|"NEW_AND_OLD_IMAGES"|"KEYS_ONLY"
  ),
  SSESpecification = list(
    Enabled = TRUE|FALSE,
    SSEType = "AES256"|"KMS",
    KMSMasterKeyId = "string"
  ),
  ReplicaUpdates = list(
    list(
      Create = list(
        RegionName = "string",
        KMSMasterKeyId = "string",
        ProvisionedThroughputOverride = list(
          ReadCapacityUnits = 123
        ),
        GlobalSecondaryIndexes = list(
          list(
            IndexName = "string",
            ProvisionedThroughputOverride = list(
              ReadCapacityUnits = 123
            )
          )
        ),
        TableClassOverride = "STANDARD"|"STANDARD_INFREQUENT_ACCESS"
      ),
      Update = list(
        RegionName = "string",
        KMSMasterKeyId = "string",
        ProvisionedThroughputOverride = list(
          ReadCapacityUnits = 123
        ),
        GlobalSecondaryIndexes = list(
          list(
            IndexName = "string",
            ProvisionedThroughputOverride = list(
              ReadCapacityUnits = 123
            )
          )
        ),
        TableClassOverride = "STANDARD"|"STANDARD_INFREQUENT_ACCESS"
      ),
      Delete = list(
        RegionName = "string"
      )
    )
  ),
  TableClass = "STANDARD"|"STANDARD_INFREQUENT_ACCESS",
  DeletionProtectionEnabled = TRUE|FALSE
)

So your format should be:

con$update_table(
  TableName = "test",
  ProvisionedThroughput = list(
    ReadCapacityUnits = 5,
    WriteCapacityUnits = 2
  ),
  GlobalSecondaryIndexUpdates = list(
    list(
      Update = list(
        IndexName = "tstatusIndex",
        ProvisionedThroughput = list(
          ReadCapacityUnits = 5,
          WriteCapacityUnits = 2
        )
      )
    )
  )
)

Let me know if this works out for you :)

oh my god that extra missing list() took so many hours of me - thx for helping solve this... not a bug, only dumb XD