Last active
December 25, 2018 23:04
-
-
Save maemichi-monosense/af36f97c17a881b84385baa7cd7e285b to your computer and use it in GitHub Desktop.
AWS scripts
This file contains hidden or 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
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'aws-sdk-support', '~> 1' | |
end | |
sts = Aws::STS::Client.new | |
pp sts.get_caller_identity | |
REGION = 'us-east-1' | |
support = Aws::Support::Client.new(region: REGION) | |
lang = ARGV[0] || 'en' # ja | |
checks = support.describe_trusted_advisor_checks(language: lang).checks | |
results = checks.lazy.map do |check| | |
result = support.describe_trusted_advisor_check_result(check_id: check.id, language: lang).result | |
[check.name, result.status] | |
end | |
pp results.to_h |
This file contains hidden or 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
require 'bundler/inline' | |
require 'set' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'aws-sdk-ec2', '~> 1' | |
end | |
ec2 = Aws::EC2::Resource.new | |
all = ec2.security_groups.map(&:id) | |
used = ec2.network_interfaces.flat_map(&:groups).map(&:group_id) | |
unused = all.to_set - used.to_set | |
groups = ec2.security_groups group_ids: unused | |
groups.each do |group| | |
puts [group.id, group.vpc_id, group.group_name].join("\t") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref