title: How to use begins_with in AWS DynamoDb js sdk?
body: <p>I have a use case to apply <strong>begins_with</strong> on the <strong>primary sort key</strong> of an AWS Dynamodb table,<br>
  I am able to query the table using begins_with key condition from the AWS Console,<br>
  I wish to achieve the same using the AWS Javascript SDK.<br></p>
  
  <p><a href="https://i.stack.imgur.com/ml5oL.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ml5oL.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/FKtbO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/FKtbO.png" alt="enter image description here"></a></p>
  
  <p><strong>I have the following fields in my table -</strong><br>
  1. user_id (<strong>Primary partition key</strong>)<br>
  2. user_relation (<strong>Primary sort key</strong>)<br><br></p>
  
  <p><strong>I tried the following code -</strong></p>
  
  <pre><code>let AWS = require('aws-sdk');
  let util = require('util');
  
  AWS.config.update({
      region: 'us-east-1'
  });
  
  let connection = new AWS.DynamoDB.DocumentClient();
  
  let params = {
      TableName: 'user_details',
      KeyConditionExpression: 'user_id = :user_id and user_relation begins_with :user_relation',
      ExpressionAttributeValues: {
          ':user_id': "1234",
          ':user_relation': "followed-by"
      }
  };
  
  console.log('getQuery Params =&gt; ', params);
  let dynamoDb = util.promisify(connection.query).bind(connection);
  let results = await dynamoDb(params);
  console.log('results =&gt; ', results);
  </code></pre>
  
  <p>I am getting a syntax error, what is the correct way to use <strong>begins_with</strong> while querying an AWS DynamoDb table?<br><br></p>
  
  <p><strong>Error -</strong><br></p>
  
  <pre><code>(node:40474) UnhandledPromiseRejectionWarning: ValidationException: Invalid KeyConditionExpression: Syntax error; token: "begins_with", near: "user_relation BE
  GINS_WITH :user_relation"
  </code></pre>
  
  <p><strong>References -</strong><br>
  <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#query-property" rel="noreferrer">https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#query-property</a><br><br>
  <a href="https://stackoverflow.com/questions/54528932/dynamodb-how-to-query-with-begins-with">DynamoDB,how to query with BEGINS_WITH</a><br><br>
  <a href="https://stackoverflow.com/questions/46543319/cant-query-dynamodb-with-begins-with-for-list-of-items">Can&#39;t Query DynamoDB with Begins_with for list of Items</a></p>