add automatic table creation

This commit is contained in:
Emil Lerch 2020-11-25 12:07:12 -08:00
parent b8f72d2705
commit bbc4920c4c
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -28,13 +28,25 @@ def ddb_url(url):
def all_etags(urls): def all_etags(urls):
response = ddb.batch_get_item(RequestItems={table: { try:
'Keys': [ddb_url(url) for url in urls], response = ddb.batch_get_item(RequestItems={table: {
}}) 'Keys': [ddb_url(url) for url in urls],
rc = {} }})
for item in response['Responses'][table]: rc = {}
rc[item['PK']['S']] = item['etag']['S'] for item in response['Responses'][table]:
return rc if 'etag' in item:
rc[item['PK']['S']] = item['etag']['S']
return rc
except Exception as ex:
printerr("Exception getting items: %s. Creating table", ex)
response = ddb.create_table(
TableName = table,
AttributeDefinitions = [
{ 'AttributeName': 'PK', 'AttributeType': 'S' }
],
KeySchema = [ { 'AttributeName': 'PK', 'KeyType': 'HASH' } ],
)
return all_etags(urls)
def create_put_request(item): def create_put_request(item):