Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: ensure lambda script paginates through all table names
Browse files Browse the repository at this point in the history
Closes #1000
  • Loading branch information
pjenvey committed Sep 12, 2017
1 parent a6795f3 commit d692c7f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

dynamodb = boto3.resource('dynamodb', region_name=REGION)
client = boto3.client('dynamodb', region_name=REGION)
paginator = client.get_paginator('list_tables')


def get_month(delta=0):
Expand All @@ -76,6 +77,12 @@ def make_rotating_tablename(prefix, delta=0):
return "{}_{:04d}_{:02d}".format(prefix, date.year, date.month)


def table_exists(tablename):
"""Determine if the specified Table exists"""
query = "contains(TableNames, {!r})".format(tablename)
return any(paginator.paginate().search(query))


def table_maintenance(event, context):
"""AWS Lambda function for ensuring the appropriate message table is
available for the next month
Expand All @@ -95,8 +102,7 @@ def table_maintenance(event, context):

# Determine if we are making the table or just verifying limits
nxt_mth_tblname = make_rotating_tablename(MESSAGE_TABLE_PREFIX, delta=1)
existing_tables = client.list_tables()["TableNames"]
if nxt_mth_tblname in existing_tables:
if table_exists(nxt_mth_tblname):
# Verify table units
nxt_mth_tbl = dynamodb.Table(nxt_mth_tblname)
nxt_limits = nxt_mth_tbl.provisioned_throughput
Expand Down

0 comments on commit d692c7f

Please sign in to comment.