Just upgrading a project to use v1.0.4 and seeing ...
# sst
r
Just upgrading a project to use v1.0.4 and seeing a problem when creating a table. I have a function that creates a table:
Copy code
createResourceTable(removalPolicy: RemovalPolicy) {
  return new sst.Table(this, 'resourceTable', {
    fields: {
      datasetId: 'string',
      resourceId: 'string',
      ttl: 'number',
    },
    primaryIndex: { partitionKey: 'datasetId', sortKey: 'resourceId' },
    cdk: {
      table: {
        pointInTimeRecovery: true,
        billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
        timeToLiveAttribute: 'ttl',
        removalPolicy,
      },
    },
  });
}
but when it’s called SST is failing with:
Copy code
TypeError: Cannot read property 'toUpperCase' of undefined
    at Table.buildAttribute (/Users/rosscoundon/Documents/GitHub/omw-pso-be/node_modules/@serverless-stack/resources/src/Table.ts:657:22)
    at Table.createTable (/Users/rosscoundon/Documents/GitHub/omw-pso-be/node_modules/@serverless-stack/resources/src/Table.ts:574:20)
    at new Table (/Users/rosscoundon/Documents/GitHub/omw-pso-be/node_modules/@serverless-stack/resources/src/Table.ts:278:10)
    at OmwPsoStack.createResourceTable (/Users/rosscoundon/Documents/GitHub/omw-pso-be/stacks/OmwPsoStack.ts:90:12)
    at new OmwPsoStack (/Users/rosscoundon/Documents/GitHub/omw-pso-be/stacks/OmwPsoStack.ts:360:32)
This points to the buildAttribute method:
Copy code
private buildAttribute(
    fields: { [key: string]: TableFieldType },
    name: string
  ): dynamodb.Attribute {
    return {
      name,
      type: dynamodb.AttributeType[
        fields[name].toUpperCase() as keyof typeof dynamodb.AttributeType
      ],
    };
  }
I can’t really see how
fields[name]
is ending up
undefined
Any thoughts?
I’ve identified the cause of this as being a table where there were fields referenced in keys that weren’t mentioned in the fields property. The odd thing is, it wasn’t the table that the stack trace referenced.
s
I ran across this issue as well after upgrading a project to SST 1.x. I had defined my PK/SK in the
fields
, but did not define the
ttl
attribute. Looks like you're having the same issue
r
That’s right, the thing that threw me was that the error was referencing the wrong place
s
Yeah, it was super confusing. I arrived at the same solution you did, but it was merely a guess
r
it’s nice to have company 🙂