Sha256: 905524f160baa579627445146214b98a8f3e56729223bb97b37d4b53c98acd28
Contents?: true
Size: 857 Bytes
Versions: 16
Compression:
Stored size: 857 Bytes
Contents
module AwsEc2::Template::Helper::AmiHelper include AwsEc2::AwsService # Example: # # latest_ami("ruby-2.5.0_*") => ami-122 # # Equivalent aws cli test command: # # $ aws ec2 describe-images --owners self --filters="Name=name,Values=ruby-2.5.0_*" | jq '.Images | length' # # Returns latest ami ami def latest_ami(query, owners=["self"]) images = search_ami(query, owners) image = images.sort_by(&:name).reverse.first if image image.image_id else puts "latest_ami helper method could not find an AMI with the query of: #{query.inspect}".colorize(:red) exit 1 end end def search_ami(query, owners=["self"]) ec2.describe_images( owners: owners, filters: [ {name: "name", values: [query]}, {name: "state", values: ["available"]} ] ).images end end
Version data entries
16 entries across 16 versions & 1 rubygems