8000 Function now waits for the DynamoDB table to be created before contin… · alxsey/aws-lambda-ddns-function@0459289 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0459289

Browse files
committed
Function now waits for the DynamoDB table to be created before continuing on.
1 parent 480d48c commit 0459289

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

union.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,7 @@ def lambda_handler(event, context):
2121
if 'DDNS' in tables['TableNames']:
2222
print 'DynamoDB table already exists'
2323
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')
4325

4426
# Set variables
4527
# Get the state from the Event stream
@@ -282,6 +264,29 @@ def lambda_handler(event, context):
282264
else:
283265
print 'No matching zone for %s' % configuration[0]
284266

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+
285290
def create_resource_record(zone_id, host_name, hosted_zone_name, type, value):
286291
"""This function creates resource records in the hosted zone passed by the calling function."""
287292
print 'Updating %s record %s in zone %s ' % (type, host_name, hosted_zone_name)

union.py.zip

31 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
0