Last active
March 18, 2019 22:41
-
-
Save pygeek/d07a82430e49f23753726ab4d4e131f8 to your computer and use it in GitHub Desktop.
Run audit of tenant - service versions in specified aws region - cluster.
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 ruby | |
require 'aws-sdk-ecs' | |
class EcsTenantAudit | |
attr_reader :region, :cluster | |
def initialize(region: "us-east-1", cluster: "ecs-q") | |
@region = region | |
@cluster = cluster | |
@ecs = Aws::ECS::Resource.new(region: region) | |
@service_arns ||= [] | |
self.retrieve_service_arns | |
@service_arns.sort! | |
end | |
def retrieve_service_arns(next_token=nil) | |
params = { cluster: @cluster, next_token: next_token } | |
services = @ecs.client.list_services(params) | |
@service_arns.push(*services.service_arns) | |
if services.next_token | |
retrieve_service_arns(services.next_token) | |
end | |
end | |
def get_results | |
@service_arns.each_slice(10) do |service_arn_batch| | |
params = { cluster: @cluster, services: service_arn_batch} | |
resp = @ecs.client.describe_services(params) | |
resp[:services].each do |service| | |
task_definition = service[:task_definition] | |
td_resp = @ecs.client.describe_task_definition({task_definition: task_definition}) | |
td_version = td_resp[:task_definition][:container_definitions].first[:image].split(':').last.sub(/^\d+\./, "") | |
puts "#{service[:service_name]} - #{td_version}" | |
end | |
end | |
puts "Total: #{@service_arns.length}" | |
end | |
end | |
EcsTenantAudit.new(cluster: "ecs-q").get_results | |
EcsTenantAudit.new(cluster: "ecs-stg").get_results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment