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

Version Path
aws-ec2-1.4.9 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.8 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.7 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.6 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.5 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.4 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.3 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.2 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.1 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.4.0 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.3.2 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.3.1 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.3.0 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.2.2 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.2.1 lib/aws_ec2/template/helper/ami_helper.rb
aws-ec2-1.2.0 lib/aws_ec2/template/helper/ami_helper.rb