Skip to content
This repository was archived by the owner on Jun 5, 2018. It is now read-only.

Commit f3cdec7

Browse files
committed
lambda: make function idempotent
Don't ever modify `ecs_cluster` as it may cause false positives in the event the lambda is executed several times in the same environment.
1 parent 4ba73c5 commit f3cdec7

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

lambda_health_check.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def get_service_for_port(port, environment):
154154

155155
return ""
156156

157-
def get_ecs_data():
157+
def get_ecs_data(clusters):
158158
data = []
159-
for cluster_name in ecs_clusters:
159+
for cluster_name in clusters:
160160
list_ec2_instances = {}
161161
list_ecs_private_ips = []
162162
list_instance_arns = {}
@@ -196,18 +196,21 @@ def get_ecs_data():
196196

197197
def lambda_handler(event, context):
198198
#print('Starting')
199-
199+
clusters = None
200200
if len(ecs_clusters) == 0:
201+
clusters = []
201202
response = ecs.list_clusters()
202203
for cluster in response['clusterArns']:
203-
ecs_clusters.append(cluster)
204+
clusters.append(cluster)
205+
else:
206+
clusters = ecs_clusters
204207

205208
#print (ecs_clusters)
206209
response = route53.list_resource_record_sets(HostedZoneId=hostedZoneId)
207-
208-
ecs_data = get_ecs_data()
210+
211+
ecs_data = get_ecs_data(clusters)
209212
#print(ecs_data)
210-
213+
211214
process_records(response, ecs_data)
212215

213216
return 'Service Discovery Health Check finished'

0 commit comments

Comments
 (0)