Created
November 29, 2017 22:22
-
-
Save chaseconey/afc1d439b19c39e444993ba9054b0b96 to your computer and use it in GitHub Desktop.
Update all ECS Agents for all Clusters in a given AWS Account
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
#!/usr/bin/env python | |
# A simple utility for updating all ecs agents in a given AWS account to the latest version | |
import boto3 | |
import botocore.session | |
import argparse | |
from colorama import init, Fore, Style | |
init() | |
parser = argparse.ArgumentParser("update-ecs-agents") | |
parser.add_argument("--profile", help="The aws profile to use", default='default') | |
args = parser.parse_args() | |
# Tell Boto 3 to use that session by default | |
print(Fore.GREEN + "Setting profile to: " + args.profile) | |
boto3.setup_default_session(profile_name=args.profile) | |
ecs = boto3.client('ecs') | |
response = ecs.list_clusters() | |
for clusterArn in response.get('clusterArns', []): | |
print(Fore.WHITE + "Starting on cluster: " + clusterArn) | |
response = ecs.list_container_instances(cluster=clusterArn, status='ACTIVE') | |
for instanceArn in response.get('containerInstanceArns', []): | |
print(Fore.WHITE + "Updating agent on instance: " + instanceArn) | |
try: | |
response = ecs.update_container_agent( | |
cluster=clusterArn, | |
containerInstance=instanceArn | |
) | |
print(Fore.GREEN + "Update successfully applied") | |
except Exception: | |
print(Fore.YELLOW + "No update available") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment