This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import datetime | |
import logging | |
import json | |
import re | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
logger.info('Loading function...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for asg in auto_scaling_groups: | |
cluster_name = next(x for x in asg['Tags'] if x['Key'] == 'cluster_name')['Value'] | |
instance_list = ecs.list_container_instances(cluster=cluster_name, status='ACTIVE') | |
instances = ecs.describe_container_instances( | |
cluster=cluster_name, | |
containerInstances=instance_list['containerInstanceArns']) | |
# all tasks running on current cluster | |
tasks = get_tasks(cluster_name) | |
# get the largest CPU reservation of any container | |
max_cpu = int(max(tasks, key=lambda x: x['cpu'])['cpu']) |