title: How to PutItem in dynamodb only if the item does not exist
body: <p>I've got a table in dynamodb that only has a partition key, and I want to put an item in the db only if there isn't another item with the same partition key in the db. </p>
  
  <p>I've tried using ConditionExpression attribute_not_exists to no avail. </p>
  
  <p>The issue is that a certain item may not already exist in the db, so attribute_not_exists fails with an
  Invalid ConditionExpression: Operator or function requires a document path; operator or function: attribute_not_exists</p>
  
  <p>Edit:
  Can you please post the full condition expression you used + the name of the table's partition key? –</p>
  
  <pre><code>Key: {
    username: event.pathParameters.username
  },
  ExpressionAttributeValues: {
    ":username": event.pathParameters.username
  },
  Item: {
      userId: event.requestContext.identity.cognitoIdentityId
  },
  ConditionExpression: "attribute_not_exists(:username)"
  </code></pre>