Skip to content

Commit

Permalink
Fix issue aws-samples#8
Browse files Browse the repository at this point in the history
- use containerListResp instead of clusterListREsp in checkContainerInstanceTaskStatus
- remove some unused variables
  • Loading branch information
Ingmar Stein committed Oct 16, 2017
1 parent 9b02651 commit 5e501e9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions code/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..'
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 5e501e9

Please sign in to comment.