title: Get attribute from dynamo db table
body: <p>im new to pyton and lambda scripting. Im trying to get a value from &quot;extension&quot; attribute from a dynamodb table with a primary partition key only.</p>
  <pre><code>from __future__ import print_function
  import boto3
  from boto3.dynamodb.conditions import Key, Attr
  import json
  dynamodb = boto3.resource('dynamodb')
  
  def lambda_handler(event, context):
      #print(event)
      extension=event['Details']['ContactData']['Attributes'].get('AgentExtension',&quot;Not Available&quot;)
      table = dynamodb.Table('mm-vm-solution-VoicemailStack-1BCDEMP76ZZA6-UsersTable-YYZ15DDH1LHR')
      try:
        response = table.query(
          IndexName= 'AgentExtensionIndex',
          KeyConditionExpression=Key('extension').eq(extension)
          )
      except ClientError as e:
          print(e.response['Error']['Message'])
          return {
                  &quot;Success&quot;:&quot;False&quot;,
                  &quot;Reason&quot;:e.response['Error']['Message']
                 }
      else:
          #item = response['Items']
          print(&quot;GetItem succeeded:&quot;)
          print(json.dumps(response))
          if &quot;Item&quot; in response:
              return {
                  &quot;Success&quot;:&quot;True&quot;
              }
          else:
              return {
                  &quot;Success&quot;:&quot;False&quot;,
                  &quot;Reason&quot;:&quot;No Records Found&quot;
              }
  </code></pre>
  <p>Dynamo db table is composed of a primary partition key &quot;agentId (String)&quot;. GSI is enabled as you can see in the below screenshot.</p>
  <p><a href="https://i.stack.imgur.com/trL7T.png" rel="nofollow noreferrer">Dynamo db table</a></p>
  <p>**** update ****
  I made it possible to retrieve the &quot;Success&quot;:&quot;True&quot; with this last part:</p>
  <pre><code> else:
          #item = response['Item']
          print(&quot;GetItem succeeded:&quot;)
          print(json.dumps(response))
          print(response['Items'])
          if &quot;Items&quot; in response:
              return{
                  &quot;Success&quot;:&quot;True&quot;,
                  &quot;Extension&quot;:response[&quot;Items&quot;][{extension}]
                  }
  </code></pre>
  <p>It is printing me this:</p>
  <pre><code>    {
    &quot;stackTrace&quot;: [
      [
        &quot;/var/task/lambda_function.py&quot;,
        30,
        &quot;lambda_handler&quot;,
        &quot;\&quot;Extension\&quot;:response[\&quot;Items\&quot;][{extension}]&quot;
      ]
    ],
    &quot;errorType&quot;: &quot;TypeError&quot;,
    &quot;errorMessage&quot;: &quot;list indices must be integers, not set&quot;
  }
  </code></pre>
  <p>I just need this output:</p>
  <pre><code>&quot;Success&quot;:&quot;True&quot;
  &quot;Extension:&quot;7777&quot;
  </code></pre>
  <p>Please help me achieve this and i will mark the answer as correct!</p>