
import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

def purge_item(item, batch):
    response = batch.delete_item(
        Key={
            'event' : item['event'],
            'id': item['id']
        }
    )

def purge_handler(event, context):
    dynamodb = boto3.resource('dynamodb')

    table = dynamodb.Table('Samples')
    filter = Attr('time').lte(decimal.Decimal(time.time()-172800))

    with table.batch_writer() as batch:
        response = table.scan(
            FilterExpression=filter
        )

        for item in response['Items']:
            purge_item(item, batch)

        while 'LastEvaluatedKey' in response:
            response = scan(
                FilterExpression=filter,
                ExclusiveStartKey=response['LastEvaluatedKey']
            )

            for item in response['Items']:
                purge_item(item, batch)

import logging
import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

logger = logging.getLogger()
logger.setLevel(logging.ERROR)

def purge_item(item, batch):
    response = batch.delete_item(
        Key={
            'event' : item['event'],
            'id': item['id']
        }
    )

def purge_handler(event, context):
    dynamodb = boto3.resource('dynamodb')

    table = dynamodb.Table('Samples')
    filter = Attr('time').lte(decimal.Decimal(time.time()-172800))

    with table.batch_writer() as batch:
        response = table.scan(
            FilterExpression=filter
        )

        for item in response['Items']:
            purge_item(item, batch)

        while 'LastEvaluatedKey' in response:
            response = scan(
                FilterExpression=filter,
                ExclusiveStartKey=response['LastEvaluatedKey']
            )

            for item in response['Items']:
                purge_item(item, batch)

Add error logging to aid tracking down future issues.
Add error logging to aid tracking down future issues.

- 
+ import logging
  import json
  import boto3
  import time
  import decimal
  from boto3.dynamodb.conditions import Key, Attr
+ 
+ logger = logging.getLogger()
+ logger.setLevel(logging.ERROR)
  
  def purge_item(item, batch):
      response = batch.delete_item(
          Key={
              'event' : item['event'],
              'id': item['id']
          }
      )
  
  def purge_handler(event, context):
      dynamodb = boto3.resource('dynamodb')
  
      table = dynamodb.Table('Samples')
      filter = Attr('time').lte(decimal.Decimal(time.time()-172800))
  
      with table.batch_writer() as batch:
          response = table.scan(
              FilterExpression=filter
          )
  
          for item in response['Items']:
              purge_item(item, batch)
  
          while 'LastEvaluatedKey' in response:
              response = scan(
                  FilterExpression=filter,
                  ExclusiveStartKey=response['LastEvaluatedKey']
              )
  
              for item in response['Items']:
                  purge_item(item, batch)
  
Add error logging to aid tracking down future issues.
## Code Before:

import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

def purge_item(item, batch):
    response = batch.delete_item(
        Key={
            'event' : item['event'],
            'id': item['id']
        }
    )

def purge_handler(event, context):
    dynamodb = boto3.resource('dynamodb')

    table = dynamodb.Table('Samples')
    filter = Attr('time').lte(decimal.Decimal(time.time()-172800))

    with table.batch_writer() as batch:
        response = table.scan(
            FilterExpression=filter
        )

        for item in response['Items']:
            purge_item(item, batch)

        while 'LastEvaluatedKey' in response:
            response = scan(
                FilterExpression=filter,
                ExclusiveStartKey=response['LastEvaluatedKey']
            )

            for item in response['Items']:
                purge_item(item, batch)

## Instruction:
Add error logging to aid tracking down future issues.
## Code After:
import logging
import json
import boto3
import time
import decimal
from boto3.dynamodb.conditions import Key, Attr

logger = logging.getLogger()
logger.setLevel(logging.ERROR)

def purge_item(item, batch):
    response = batch.delete_item(
        Key={
            'event' : item['event'],
            'id': item['id']
        }
    )

def purge_handler(event, context):
    dynamodb = boto3.resource('dynamodb')

    table = dynamodb.Table('Samples')
    filter = Attr('time').lte(decimal.Decimal(time.time()-172800))

    with table.batch_writer() as batch:
        response = table.scan(
            FilterExpression=filter
        )

        for item in response['Items']:
            purge_item(item, batch)

        while 'LastEvaluatedKey' in response:
            response = scan(
                FilterExpression=filter,
                ExclusiveStartKey=response['LastEvaluatedKey']
            )

            for item in response['Items']:
                purge_item(item, batch)
