title: boto3 resource for querying dynamodb : Query condition missed key schema element
body: <p>I have a table as : AdvgCountries which has two columns
  a.  CountryId (String) (Parition Key)
  b.  CountryName(String) Sort Key
  While creating the table , I created with only Partition Key and then later added a Global Secondary Index with Index name as:</p>
  <pre><code>CountryName-index
  Type : GSI
  Partition key : CountryId
  Sort Key : CountryName
  </code></pre>
  <p>I am able to retrieve <code>CountryName</code> based upon <code>CountryId</code> but unable to retrieve CountryId based upon CountryName. Based upon my reading I found that there are options to do this by providing <code>indexname</code> but I get the following error:</p>
  <blockquote>
  <p>botocore.exceptions.ClientError: An error occurred
  (ValidationException) when calling the Query operation: Query
  condition missed key schema element: CountryId</p>
  </blockquote>
  <pre class="lang-python prettyprint-override"><code>import boto3
  import json
  import os
  from boto3.dynamodb.conditions import Key, Attr
  
  def query_bycountryname(pCountryname, dynamodb=None):
      if not dynamodb:
          dynamodb = boto3.resource('dynamodb', endpoint_url=&quot;https://dynamodb.us-east-1.amazonaws.com&quot;)
  
      table = dynamodb.Table('AdvgCountires')
      print(f&quot;table&quot;)
      attributes = table.query(
          IndexName=&quot;CountryName-index&quot;,
          KeyConditionExpression=Key('CountryName').eq(pCountryname),
      )
      if 'Items' in attributes and len(attributes['Items']) == 1:
          attributes = attributes['Items'][0]
  
      print(f&quot;before return&quot;)
      return attributes
  
  if __name__ == '__main__':
  
  
      CountryName = &quot;India&quot;
      print(f&quot;Data for {CountryName}&quot;)
      countries = query_bycountryname(CountryName)
      for country in countries:
         print(country['CountryId'], &quot;:&quot;, country['CountryName'])
  </code></pre>
  <p>Any help is appreciated.</p>