PAY_PER_REQUEST, but "Both ReadCapacityUnits and WriteCapacityUnits must be specified for index"

I keep getting the error:

An error occurred: ResponsesTable - One or more parameter values were invalid: Both ReadCapacityUnits and WriteCapacityUnits must be specified for index: TaskIdIndex (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException

Using the following table definition:

    ResponsesTable:
      Type: AWS::DynamoDB::Table
      DeletionPolicy: Retain
      Properties:
        TableName: ${self:provider.environment.RESPONSES_TABLE}
        BillingMode: PAY_PER_REQUEST
        KeySchema:
          - AttributeName: responseId
            KeyType: HASH
          - AttributeName: taskId
            KeyType: RANGE
        AttributeDefinitions:
          - AttributeName: responseId
            AttributeType: S
          - AttributeName: taskId
            AttributeType: S
        GlobalSecondaryIndexes:
          - IndexName: TaskIdIndex
            KeySchema:
              - KeyType: HASH
                AttributeName: taskId
            Projection:
              ProjectionType: ALL
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES

I can get around this by manually editing the table using the console but it kind of defeats the purpose of “infrastructure as code”.

Any ideas?

Did you previously have the table configured with WCU and RCU?

I didn’t think so, but thankfully I haven’t launched yet so I just recreated everything.

Question, though - it seems that one can’t ever alter tables using the AWS console or else the serverless.yml will be out of sync and future deployment won’t work. Is that fair to say?

Its generally a bad idea to alter anything, not just DynamoDB tables. This is because of CloudFormation which the Serverless Framework leverages for deploying your infrastructure as well as maintaining state of your stack.

1 Like