I’m creating the following table within my stack: ...
# help
d
I’m creating the following table within my stack:
Copy code
// Create the DynamoDB table
    const customersTable = new sst.Table(this, "Customers", {
      fields: {
        pk: sst.TableFieldType.STRING,
        sk: sst.TableFieldType.STRING,
        createdAt: sst.TableFieldType.STRING,
        customerId: sst.TableFieldType.STRING,
        email: sst.TableFieldType.STRING,
        firstName: sst.TableFieldType.STRING,
        lastName: sst.TableFieldType.STRING,
        phone: sst.TableFieldType.STRING,
      },
      primaryIndex: { partitionKey: "pk", sortKey: "sk" },
    });
But i realized that
[createdAt, customerId, email, firstName, lastName, phone]
are all values that aren’t being indexed by dynamoDb they’re just values. Should I have them here?
g
As far as I know putting non-indexed fields there does nothing as dynamo is supposed to be schema-less
d
yea that was what I was thinking. So really the only values in here should be GSI and Local Indexes I guess?
g
Thats what I do
d
thanks garret
b
note that KeySchema changes does trigger replacement of dynamodb so I’d guess any fields you define where you have, would fall into this replacement requirement: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-keyschema
so yeah, only the index pk/sk stuff in defined fields, everything else floating
imho
t
Putting fields that are not used in a key schema will result in an error I think
d
The create works okay. So I think it's ignored in the declaration.
t
Ooh cool TIL. I remember getting errors like this when using cloudformation.
Property AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes
Is this an SST or cdk feature I wonder. Or have cloudformation fixed this
b
yeah, I think this is a CDK thing. Although looking at SST’s table construct, the fields are used when building index/primary/sort keys - neither sst or cdk have any real mention of AttributeDefinitions from cloudformation https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.Table.html https://github.com/serverless-stack/serverless-stack/blob/09573c6f261e5fd16d5931e0f4f094e4fa272817/packages/resources/src/Table.ts
so yeah, seems like fields not used in indexes just get tossed and not passed to cloudform in the end
from what I see at least
d
ya same