hope to find you well :)
I am trying to create a DynamoDB table with a GSI using the aws CDK. Here is my code:
export class LeaderboardsTableStack extends cdk.Stack {
public leaderboardsTable
constructor(scope: Construct, id: string, props: LeaderboardsTableStackProps) {
super(scope, id, props)
this.leaderboardsTable = new dynamodb.Table(this, `${props.STAGE}leaderboardsTable`, {
tableName: `${props.STAGE}Leaderboards`,
partitionKey: { name: 'PK', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'SK', type: dynamodb.AttributeType.STRING },
removalPolicy: cdk.RemovalPolicy.DESTROY,
billingMode: dynamodb.BillingMode.PROVISIONED,
stream: dynamodb.StreamViewType.NEW_AND_OLD_IMAGES
})
this.leaderboardsTable.addGlobalSecondaryIndex({
indexName: 'GSI1',
partitionKey: { name: 'SK', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'GSI1SK', type: dynamodb.AttributeType.STRING },
projectionType: dynamodb.ProjectionType.INCLUDE,
nonKeyAttributes: ['participant_display_name']
})
}
}
As you can see, I am trying to specify that the GSI should have as the partition key the SK from the main table, and as a sort key the attribute GSI1SK that only certain items have.
However, for some reason, in the GSI table the items simply get replicated with the same PK and SK, but only those that have the GSI1SK attribute (at least this is going according to plan lol).
What am I doing wrong here? I am quite puzzled honestly :/
Even from the documentation, this should work as I intended right?
If have any tip or idea, please feel free to share! Thank you in advance!