title: How to delete all the items in the dynamodb with boto3
body: <p>My Code is below is to delete contents from the table name <code>details</code></p>
  <ul>
  <li>The below code will delete some items according to <code>Capacity</code> of dynamodb which is working fine</li>
  <li>How to delete all the items</li>
  </ul>
  <pre><code>    import boto3
      def lambda_handler(event, context):
          try:
              table_name = 'details'
              dynamodb = boto3.resource('dynamodb')
              table = dynamodb.Table(table_name)
              scan = table.scan()
              with table.batch_writer() as batch:
                  for each in scan['Items']:
                      batch.delete_item(
                          Key={
                              'id': each['id']
                          }
                      )
          except Exception as e:
             print (e)
  </code></pre>
  <p>I wrote with <code>while</code> loop with a Flag condition.</p>
  <pre><code>   import boto3
      def lambda_handler(event, context):
          try:
              flag = False
              table_name = 'details'
              dynamodb = boto3.resource('dynamodb')
              table = dynamodb.Table(table_name)
              scan = table.scan()
              while True:
                  with table.batch_writer() as batch:
                      for each in scan['Items']:
                          if each is not None:
                              batch.delete_item(
                                   Key={
                                   'id': each['id']
                                   }
                               )
                           else:
                              Flag = True
          except Exception as e:
             print (e)
  
  </code></pre>