add automatic table creation
This commit is contained in:
parent
b8f72d2705
commit
bbc4920c4c
12
etags.py
12
etags.py
|
@ -28,13 +28,25 @@ def ddb_url(url):
|
||||||
|
|
||||||
|
|
||||||
def all_etags(urls):
|
def all_etags(urls):
|
||||||
|
try:
|
||||||
response = ddb.batch_get_item(RequestItems={table: {
|
response = ddb.batch_get_item(RequestItems={table: {
|
||||||
'Keys': [ddb_url(url) for url in urls],
|
'Keys': [ddb_url(url) for url in urls],
|
||||||
}})
|
}})
|
||||||
rc = {}
|
rc = {}
|
||||||
for item in response['Responses'][table]:
|
for item in response['Responses'][table]:
|
||||||
|
if 'etag' in item:
|
||||||
rc[item['PK']['S']] = item['etag']['S']
|
rc[item['PK']['S']] = item['etag']['S']
|
||||||
return rc
|
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):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user