title: AWS SDK .NET DynamoDB ASYNC
body: <p>I am trying to use AWS SDK for .NET Core.</p>
  
  <ul>
  <li>Create a table to count views on videos.</li>
  <li>Add a view count for a day.</li>
  <li>Increment existing count for a day.</li>
  <li>Query for video counts between two dates for a video.</li>
  </ul>
  
  <p>.NET Core AWS SDK uses Async methods which are not documented in AWS. There is a feature request on their github page for this to happen.... but it is dated from last year. (<a href="https://github.com/aws/aws-sdk-net/issues/787" rel="nofollow noreferrer">https://github.com/aws/aws-sdk-net/issues/787</a>)</p>
  
  <p>CREATE THE TABLE</p>
  
  <p>This works and creates a table on the AWS Console.</p>
  
  <pre><code>var ctRequest = new CreateTableRequest
  {
      AttributeDefinitions = new List&lt;AttributeDefinition&gt;()
      {
          new AttributeDefinition
          {
              AttributeName = "ViewUid",
              AttributeType = ScalarAttributeType.S
          },
          new AttributeDefinition
          {
              AttributeName = "ViewDate",
              AttributeType = ScalarAttributeType.S
          }
      },
      KeySchema = new List&lt;KeySchemaElement&gt;
      {
          new KeySchemaElement
          {
              AttributeName = "ViewUid",
              KeyType = KeyType.HASH //Partition key
          },
          new KeySchemaElement
          {
              AttributeName = "ViewDate",
              KeyType = KeyType.RANGE
          }
      },
      ProvisionedThroughput = new ProvisionedThroughput
      {
          ReadCapacityUnits = 5,
          WriteCapacityUnits = 6
      },
      TableName = _settings.AWSDynamoDBViewCountTable
  };
  
  var response = _client.CreateTableAsync(ctRequest).Result;
  </code></pre>
  
  <p>UPDATE AND ITEM WITH AUTO-INCREMENT A FIELD</p>
  
  <p>This, sadly, is where i hit issues. The old docs are found here under the Atomic Counter section. (<a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetItemCRUD.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetItemCRUD.html</a>)</p>
  
  <blockquote>
    <p>Invalid ConditionExpression: Syntax error; token: \"SET\", near: \"SET
    VC\"</p>
  </blockquote>
  
  <pre><code>var viewData = new Document();
  viewData["ViewUid"] = videoUid; //Table entry UID
  viewData["VideoId"] = videoId;  // Video ID
  viewData["ViewDate"] = date;
  viewData["ViewCount"] = 0;
  //Document result = await _viewCountTable.PutItemAsync(viewData);
  
  Expression expr = new Expression();
  expr.ExpressionStatement = "SET #VC = #VC + :val";
  expr.ExpressionAttributeValues[":val"] = 1;
  expr.ExpressionAttributeNames["#VC"] = "ViewCount";
  var updateConfig = new UpdateItemOperationConfig() { 
      ConditionalExpression = expr,
      ReturnValues = ReturnValues.UpdatedNewAttributes
  };
  
  var result = await _viewCountTable.UpdateItemAsync(viewData, updateConfig);
  return result;
  </code></pre>
  
  <p>QUERY FOR DATE RANGE</p>
  
  <p>Get one video's view count for a date range.</p>
  
  <pre><code>string queryTimeSpanStartString = dateFrom.ToString(AWSSDKUtils.ISO8601DateFormat);
  string queryTimeSpanEndString = dateTo.ToString(AWSSDKUtils.ISO8601DateFormat);
  var request = new QueryRequest
  {
      TableName = _settings.AWSDynamoDBViewCountTable,
      KeyConditions = new Dictionary&lt;string, Condition&gt;()
      {
          {
              "VideoId",  new Condition()
              {
                  ComparisonOperator = "EQ",
                  AttributeValueList = new List&lt;AttributeValue&gt;()
                  {
                      new AttributeValue { S = videoId }
                  }
              }
          },
          {
              "ViewDate",
              new Condition
              {
                  ComparisonOperator = "BETWEEN",
                  AttributeValueList = new List&lt;AttributeValue&gt;()
                  {
                      new AttributeValue { S = queryTimeSpanStartString },
                      new AttributeValue { S = queryTimeSpanEndString }
                  }
              }
          }
      }
  };
  
  var response = await _client.QueryAsync(request);
  </code></pre>
  
  <p>Any help would be appreciated.</p>