How do you query using an index in the Architect Serverless Framework?

90 Views Asked by At

I am trying to query using an index but keep getting this error:

ValidationException: Query condition missed key schema element: trackID

Here is my .arc file

@tables
skytracks
  trackID *String
  _ttl TTL

@indexes
skytracks
  skyTrackType *String

Here is the relevant piece of the http get handler:

const skyTrackType = req.queryStringParameters.skytracktype
const data = await arc.tables()
const trackingData = await data.skytracks.query({
      KeyConditionExpression: `skyTrackType = :skyTrackType`,
      ExpressionAttributeValues: {
        ':skyTrackType': skyTrackType
      }
    })
1

There are 1 best solutions below

1
Neil Hoff On

Architect automatically names the index attribute-index

This needs to be added to the query in the question: IndexName: 'skyTrackType-index'

const trackingData = await data.skytracks.query({
      KeyConditionExpression: `skyTrackType = :skyTrackType`,
      IndexName: 'skyTrackType-index',
      ExpressionAttributeValues: {
        ':skyTrackType': skyTrackType
      }
    })