title: In aws-cli, how to delete items from DynamoDB based on a condition?
body: <p>I'm using AWS CLI and having issues deleting rows based on a condition</p>
  
  <p>I have a file_name key and I'd like to remove all keys containing "20200322".</p>
  
  <p>Command</p>
  
  <pre><code>aws dynamodb delete-item \
      --table-name "logs" \
      --condition-expression "contains(file_name, :file_name)" \
      --expression-attribute-names file://expression.json \
      --key file://key.json
  </code></pre>
  
  <p>expression.json - the variables to use in the contains</p>
  
  <pre><code>{
      ":file_name": {
          "S": "20200322"
      }
  }
  </code></pre>
  
  <p>key.json - I don't understand the point of this file</p>
  
  <pre><code>{
      "file_name": {
          "S": "20200322"
      }
  }
  </code></pre>
  
  <p>Error</p>
  
  <blockquote>
    <p>Parameter validation failed: Invalid type for parameter
    ExpressionAttributeNames.:file_name, value: OrderedDict([(u'S',
    u'20200322')]), type: , valid types:
    </p>
  </blockquote>
  
  <p>Questions</p>
  
  <ul>
  <li>How do I delete a single entry based on a contains condition?</li>
  <li>Why is the key mandatory if I'm using the <code>--expression-attribute-names</code> switch? What does the key need to be?</li>
  <li>What is the difference between <code>--expression-attribute-values</code> and <code>--expression-attribute-names</code></li>
  </ul>
  
  <p>Reference</p>
  
  <ul>
  <li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html" rel="nofollow noreferrer">DynamoDB > Condition Expressions</a></li>
  <li><a href="https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html#API_DeleteItem_RequestSyntax" rel="nofollow noreferrer">DynamoDB > API_DeleteItem_RequestSyntax</a></li>
  </ul>