From 5e501e9de9bdafd86842be670c11b5d48940ca3a Mon Sep 17 00:00:00 2001 From: Ingmar Stein Date: Mon, 16 Oct 2017 09:39:36 +0200 Subject: [PATCH] Fix issue #8 - use containerListResp instead of clusterListREsp in checkContainerInstanceTaskStatus - remove some unused variables --- code/index.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/code/index.py b/code/index.py index ed5df30..030843f 100644 --- a/code/index.py +++ b/code/index.py @@ -30,7 +30,7 @@ """ def publishToSNS(message, topicARN): logger.info("Publish to SNS topic %s",topicARN) - snsResponse = snsClient.publish( + snsClient.publish( TopicArn=topicARN, Message=json.dumps(message), Subject='Publishing SNS message to invoke lambda again..' @@ -63,7 +63,7 @@ def checkContainerInstanceTaskStatus(Ec2InstanceId): paginator = ecsClient.get_paginator('list_container_instances') clusterListPages = paginator.paginate(cluster=clusterName) for containerListResp in clusterListPages: - containerDetResp = ecsClient.describe_container_instances(cluster=clusterName, containerInstances=clusterListResp[ + containerDetResp = ecsClient.describe_container_instances(cluster=clusterName, containerInstances=containerListResp[ 'containerInstanceArns']) logger.debug("describe container instances response %s",containerDetResp) @@ -83,7 +83,7 @@ def checkContainerInstanceTaskStatus(Ec2InstanceId): else: # Make ECS API call to set the container status to DRAINING logger.info("Make ECS API call to set the container status to DRAINING...") - ecsResponse = ecsClient.update_container_instances_state(cluster=clusterName,containerInstances=[containerInstanceId],status='DRAINING') + ecsClient.update_container_instances_state(cluster=clusterName,containerInstances=[containerInstanceId],status='DRAINING') # When you set instance state to draining, append the containerInstanceID to the message as well tmpMsgAppend = {"containerInstanceId": containerInstanceId} break @@ -120,7 +120,6 @@ def lambda_handler(event, context): lifecyclehookname = None clusterName = None tmpMsgAppend = None - completeHook = 0 logger.info("Lambda received the event %s",event) logger.debug("records: %s",event['Records'][0]) @@ -173,7 +172,6 @@ def lambda_handler(event, context): logger.debug("msgResponse %s and time is %s",msgResponse, datetime.datetime) # If tasks are NOT running... elif tasksRunning == 0: - completeHook = 1 logger.debug("Setting lifecycle to complete;No tasks are running on instance, completing lifecycle action....") try: