title: DynamoDB update a counter (or insert a key)
body: <p>I have a function that is producing <code>(some_key, some_value)</code> pairs, that I want to put in my DynamoDB. If the item with key <code>some_key</code> is already present, I want to add <code>some_value</code> to the <code>value</code> attributes. Otherwise I want to create such item. Following the example in <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html" rel="noreferrer">the docs</a> it seems that the function <code>if_not_exists</code> should do what I want. I am having troubles with the syntax, because my code returns an error:</p>
  
  <pre><code>&gt;&gt;&gt;&gt; table.update_item(
          Key={
              'key': my_key
          },
          UpdateExpression="set my_value = if_not_exist(my_value + :inc, :inc)",
  
          ExpressionAttributeValues={
              ':inc': my_increment,
          },
          ReturnValues="UPDATED_NEW"
      )
  
  ClientError: An error occurred (ValidationException) when calling the UpdateItem operation: 
  Invalid UpdateExpression: Syntax error; token: "+", near: "coocc + :val"
  </code></pre>