Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamodb : not creating correct GSI #26561

Closed
ETisREAL opened this issue Jul 28, 2023 · 3 comments
Closed

dynamodb : not creating correct GSI #26561

ETisREAL opened this issue Jul 28, 2023 · 3 comments
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@ETisREAL
Copy link

Describe the bug

Hello, hope you are doing fine :)

I am trying to create a dynamodb table with a GSI. This is the 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']
        })

    }
}

Expected Behavior

Shouldn't the code above create a GSI with items that have a partition key 'SK' and a sort key 'GSI1SK'?

Current Behavior

When I deploy the above code, the GSI simply copies over the PK as primary key and SK as sort key (only for the items that conatain the GSI1SK, at least this part goes according to plan lol)

Reproduction Steps

Try to launch the above code and check the GSI creation schema

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.88

Framework Version

No response

Node.js Version

v18.16

OS

Linux - Ubuntu

Language

Typescript

Language Version

No response

Other information

No response

@ETisREAL ETisREAL added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 28, 2023
@github-actions github-actions bot added the @aws-cdk/aws-dynamodb Related to Amazon DynamoDB label Jul 28, 2023
@pahud
Copy link
Contributor

pahud commented Jul 31, 2023

Can you share the cdk synth for the Table resource especially the GlobalSecondaryIndex property?

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jul 31, 2023
@ETisREAL
Copy link
Author

Hello @pahud . The issue was simply that I wasn't querying the index correctly.

For reference, I was still using PK and SK as key attributes even though I was querying on the GSI1 index, where I am supposed to use SK and GSI1SK.

Thank you @pahud for reaching out :)

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB bug This issue is a bug. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants