@@ -21,25 +21,7 @@ def lambda_handler(event, context):
21
21
if 'DDNS' in tables ['TableNames' ]:
22
22
print 'DynamoDB table already exists'
23
23
else :
24
- dynamodb_client .create_table (
25
- TableName = 'DDNS' ,
26
- AttributeDefinitions = [
27
- {
28
- 'AttributeName' : 'InstanceId' ,
29
- 'AttributeType' : 'S'
30
- },
31
- ],
32
- KeySchema = [
33
- {
34
- 'AttributeName' : 'InstanceId' ,
35
- 'KeyType' : 'HASH'
36
- },
37
- ],
38
- ProvisionedThroughput = {
39
- 'ReadCapacityUnits' : 4 ,
40
- 'WriteCapacityUnits' : 4
41
- }
42
- )
24
+ create_table ('DDNS' )
43
25
44
26
# Set variables
45
27
# Get the state from the Event stream
@@ -282,6 +264,29 @@ def lambda_handler(event, context):
282
264
else :
283
265
print 'No matching zone for %s' % configuration [0 ]
284
266
267
+ def create_table (table_name ):
268
+ dynamodb_client .create_table (
269
+ TableName = table_name ,
270
+ AttributeDefinitions = [
271
+ {
272
+ 'AttributeName' : 'InstanceId' ,
273
+ 'AttributeType' : 'S'
274
+ },
275
+ ],
276
+ KeySchema = [
277
+ {
278
+ 'AttributeName' : 'InstanceId' ,
279
+ 'KeyType' : 'HASH'
280
+ },
281
+ ],
282
+ ProvisionedThroughput = {
283
+ 'ReadCapacityUnits' : 4 ,
284
+ 'WriteCapacityUnits' : 4
285
+ }
286
+ )
287
+ table = dynamodb_resource .Table (table_name )
288
+ table .wait_until_exists ()
289
+
285
290
def create_resource_record (zone_id , host_name , hosted_zone_name , type , value ):
286
291
"""This function creates resource records in the hosted zone passed by the calling function."""
287
292
print 'Updating %s record %s in zone %s ' % (type , host_name , hosted_zone_name )
0 commit comments