I'm trying to add a Global Secondary Index to an existing DynamoDB table that is defined thusly in the CDK:
const itemsTable = new Table(this, config.DYNAMODB_ID, {
tableName: config.DYNAMODB_ID,
partitionKey: { name: 'itemGuid', type: AttributeType.STRING },
billingMode: BillingMode.PAY_PER_REQUEST,
removalPolicy: RemovalPolicy.RETAIN,
pointInTimeRecovery: true,
deletionProtection: true,
});
itemsTable.addGlobalSecondaryIndex({
indexName: 'ItemsByType',
partitionKey: { name: 'type', type: AttributeType.STRING },
projectionType: ProjectionType.KEYS_ONLY,
});
And I get an error as follows:
Resource handler returned message: "One or more parameter values were invalid: Both ReadCapacityUnits and WriteCapacityUnits must be specified for index: ItemsByType"
This despite the fact that the table is PAY_PER_REQUEST and according to the documentation I cannot specify these values, and if I do this:
assetTable.addGlobalSecondaryIndex({
indexName: 'AssetsByType',
partitionKey: { name: 'type', type: AttributeType.STRING },
projectionType: ProjectionType.KEYS_ONLY,
readCapacity: 5,
writeCapacity: 5,
});
I instead get this error:
Error: you cannot provision read and write capacity for a table with PAY_PER_REQUEST billing mode
For what it's worth, it seems like this error gets thrown immediately on trying to run the deploy:
and the other one, demanding "ReadCapacityUnits" and "WriteCapacityUnits", gets thrown after it starts the deploy and works its way through to the part where it would be adding the index.