I want to insert an item on a GSI, however the AWS SDK library doesn't seem to cooperate.
This is the relevant code:
const updateLeaderbordAggreagte = async (documentClient, leaderboardPK, tournamentPoints, participant) => {
try {
const putLeaderboardScore = new PutItemCommand({
TableName: process.env.TABLE_NAME,
IndexName: 'GSI1',
Item: {
'GSI1-PK': leaderboardPK,
'GSI1-SK': `${tournamentPoints.padStart(5, '0')}#${participant}`,
}
})
await documentClient.send(putLeaderboardScore)
} catch (error) {
console.error('Error adding leaderboard: ', error)
}
}
When I run the code, I don't get any error, but the items don't get inserted. The argument IndexName is not even suggested by intellisense, I tried to use it because that is how you do it with boto3.
For reference, this is the table and index code:
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: 'GSI1-PK', type: dynamodb.AttributeType.STRING },
sortKey: { name: 'GSI1-SK', type: dynamodb.AttributeType.STRING },
projectionType: dynamodb.ProjectionType.KEYS_ONLY
})