1

So, with a very simple DynamoDB table, with Primary key let's say: Address: string (eg: '1 someRd,someCity,someCounty'

and a GSI: Postcode: string

If I try to manually add an item to the table, with just an Address field and no Postcode, it throws an error: One or more parameter values are not valid. A value specified for a secondary index key is not supported. The AttributeValue for a key attribute cannot contain an empty string value. IndexName: Postcode, IndexKey: Postcode

I assumed that sparse GSI's were allowed as per: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general-sparse-indexes.html

So, if we set a GSI does that field need to be included on every item in the table?

Leigh Mathieson
  • 1,658
  • 2
  • 17
  • 25
  • 1
    You do not need to specify the GSI key on every item in the table. From the error, it sounds like Postcore is being set to an empty string (vs not being there at all). Csn you share how you are performing the insert? – Seth Geoghegan Sep 20 '20 at 12:29
  • 1
    Thanks @SethGeoghegan yes that led me to the issue.. It is just when you try to manually add an item via the aws web console, and are helpfully presented in the console with all the fields specified in my serverless template yaml, if you don't also 'remove' those fields (in the console) that you don't apply a non-empty string to, then it thinks you're trying to assign an empty string! I assumed it would default to a null field than an empty string - as it appears you can't have an empty string there safe to assume it's not a required field! Thanks Seth – Leigh Mathieson Sep 20 '20 at 12:52
  • I was trying the same as you, you saved me some time, thank you :) – Carlos Martinez Nov 18 '20 at 00:21

0 Answers0