title: Dynamo DB leader board within an Alexa Skill
body: <p>I am attempting to create a leader board using dynamo db for an quiz style Alexa skill. I have set up the table and users are added to the table with their appropriate data e.g.:</p>
  
  <pre><code>Item: {
      "PlatformId": 2,
      "UserId": 12345,
      "Score": 100,
      "NickName": "scott",
      "Sport": "football",
  }
  </code></pre>
  
  <p>In my table the Primary key is their UserId, the sort key is the PlatformId (this is the same for all users). I have a secondary global index which sets the platformId as the primary key, and the score as the sort key.</p>
  
  <p>In this leader board i want users to be ranked, the highest scorer being number 1, my first attempt at this was to scan the table using the secondary index, this nicely returned all the users sorted by score, however with the potential to have thousands of users on this leader board, i discovered that the time to scan a table with 10000+ users exceeds the 8 second response time that Alexa skills have. This causes the skill to error and close.</p>
  
  <p>Before the response time exceeded, i was using the LastEvaluatedKey to perform an extra scan if the first one didn't cover the entire table, but on this second scan is when the response time limit was exceeded. Annoyingly it's just taking too long to scan the table.</p>
  
  <pre><code>dbHelper.prototype.scanGetUsers = (ad, newParams = null) =&gt; {
  return new Promise((resolve, reject) =&gt; {
      let params = {};
      if (newParams != null) {
          params = newParams
      } else {
          params = {
              TableName: tableName,
              IndexName: 'PlatformId-Score-index',
              FilterExpression: "Score &gt;= :s AND PlatformId = :p",
              ProjectionExpression: `NickName, Sport, Score`,
              // Limit: 10,
              ExpressionAttributeValues: {
                  ":p": User.PlatformId,
                  ":s": User.Score,
              },
          }
      }
  
      docClient.scan(params, function (err, data) {
          if (err || !data) {
              console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
              return reject(JSON.stringify(err, null, 2))
          } else {
              console.log("scan users data succeeded:", JSON.stringify(data, null, 2));
              if(data.LastEvaluatedKey) {
                  console.log("found a LastEvalutedKey, Continuing scan");
                  params.ExclusiveStartKey = data.LastEvaluatedKey;
                  data = data.concat(this.scanGetUsers(ad, params));
              }
              resolve(data);
          }
      });
  });
  </code></pre>
  
  <p>}</p>
  
  <p>Is there a way to work around these issues that i haven't explored yet? Or a way to create a leader board with dynamo db that can be structured in an easier way?</p>