Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created May 29, 2019 05:51
Show Gist options
  • Save fujiwara/e0d891c0c1020c9769deeb259738486d to your computer and use it in GitHub Desktop.
Save fujiwara/e0d891c0c1020c9769deeb259738486d to your computer and use it in GitHub Desktop.
Visualize container dependencies from ECS task definition JSON.
#!/usr/bin/env perl
use 5.12.1;
use warnings;
use JSON::PP;
my $file = shift;
open my $in, "<", $file or die $!;
my $taskdef = JSON::PP::decode_json(do { local $/ = undef; <$in> });
my $g = $file;
$g =~ s/[^\w]/_/g;
say "digraph $g {";
for my $c (@{$taskdef->{taskDefinition}->{containerDefinitions}}) {
my $name = $c->{name};
for my $dep (@{$c->{dependsOn}}) {
printf qq{ %s -> %s [label = "%s"];\n},
$name, $dep->{containerName}, $dep->{condition};
}
}
say "}";
#!/usr/bin/env ruby
require 'json'
file = ARGV[0]
taskdef = open(file) do |f|
JSON.load(f)
end
gname = file.gsub(/[^\w]/, '_')
puts "digraph #{gname} {"
taskdef['taskDefinition']['containerDefinitions'].each do |c|
name = c['name']
c['dependsOn']&.each do |dep|
puts " #{name} -> #{dep['containerName']} [label = \"#{dep['condition']}\"];"
end
end
puts '}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment