SOLVED - You can only do updates via a PK, you can...
# help
d
SOLVED - You can only do updates via a PK, you can’t do them with a GSIPK so I had to swap them 🎉 . Thanks to Garret for that. I’m doing something goofy with a DynamoDB request. Or I set up a SKI incorrectly (seems unlikely) I recently added a GSI to my table
Copy code
customersTable.addGlobalIndexes({
      gsi1pk: {
        partitionKey: "gsi1pk",
        type: sst.TableFieldType.STRING,
      },
    });
I can see it in my Indexes so that appears to have worked. When I add params to put like so…
Copy code
const params = {
      TableName: process.env.TABLE_NAME,
      Item: {
        pk: `SHOP#${shop}PHONE#${phoneNumber}`,
        sk: `SID#${messageSid}`,
        gsi1pk: `SID#${messageSid}`,
        messageStatus,
      },
    };

    await dynamoDb.put(params);
the item is inserted in the table and I can see it 🎉 However, when I try to update that value
Copy code
const values = {
    TableName: process.env.TABLE_NAME,
    Key: {
      gsi1pk: `SID#${messageSid}`,
      sk: `SID#${messageSid}`,
    },
    UpdateExpression: "SET messageStatus = :messageStatus",
    ExpressionAttributeValues: {
      ":messageStatus": smsStatus,
    },
  };

  await dynamoDb.update(values);
It’s not obvious to me what’s wrong.
Oh this is because it’s not in my schema for some reason
I got it so now its in my schema… so that’s a win
Current status of this is that it’s a typo - i’ll be so upset if i’m right. Upset and happy. But upset because I wasted everyones time Not a typo. I don’t see it
g
You cant update an item by a secondary index only query.
d
I don’t think I understand that sentence
g
You can only update an item by the primary key. GSI's are only allowed to be queried
d
oh really. So, I should swap the PK and GSI
Nah somehow that isn’t it either. It must be on the PUT because I don’t ever get use the GSI. Like I can see that I’m not adding any to the indexes in the console Oh nevermind I think I see