scan_table.py 523 B

12345678910111213141516171819202122
  1. """
  2. Task to scan a DynamoDB table
  3. """
  4. import boto3
  5. from boto3.dynamodb.types import TypeDeserializer
  6. from decorators import with_logging
  7. from boto_utils import paginate, deserialize_item
  8. ddb_client = boto3.client("dynamodb")
  9. deserializer = TypeDeserializer()
  10. @with_logging
  11. def handler(event, context):
  12. results = paginate(
  13. ddb_client, ddb_client.scan, "Items", TableName=event["TableName"]
  14. )
  15. items = [deserialize_item(result) for result in results]
  16. return {"Items": items, "Count": len(items)}