Skip to content

Instantly share code, notes, and snippets.

@maemichi-monosense
Last active December 25, 2018 23:04
Show Gist options
  • Save maemichi-monosense/af36f97c17a881b84385baa7cd7e285b to your computer and use it in GitHub Desktop.
Save maemichi-monosense/af36f97c17a881b84385baa7cd7e285b to your computer and use it in GitHub Desktop.
AWS scripts
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
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