Skip to content

Instantly share code, notes, and snippets.

View depop-blog's full-sized avatar

depop-blog

View GitHub Profile
@depop-blog
depop-blog / high_level.py
Created June 27, 2018 15:38
Ahead of time scheduling on ECS/EC2: high_level.py
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'])
@depop-blog
depop-blog / full_metric_lambda.py
Created June 27, 2018 15:39
Ahead of time scheduling on ECS/EC2: full_metric_lambda.py
import boto3
import datetime
import logging
import json
import re
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.info('Loading function...')