Sha256: 1d6da9589c9d2692a30f5d708901e05f5511f653169c6095648eab4be30c258a

Contents?: true

Size: 1.81 KB

Versions: 37

Compression:

Stored size: 1.81 KB

Contents

require "aws-sdk-cloudformation"

module Cfn
  module AwsService
    def cfn
      @cfn ||= Aws::CloudFormation::Client.new
    end

    def stack_exists?(stack_name)
      return true if testing_update?
      return false if @options[:noop]

      exist = nil
      begin
        # When the stack does not exist an exception is raised. Example:
        # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
        resp = cfn.describe_stacks(stack_name: stack_name)
        exist = true
      rescue Aws::CloudFormation::Errors::ValidationError => e
        if e.message =~ /does not exist/
          exist = false
        elsif e.message.include?("'stackName' failed to satisfy constraint")
          # Example of e.message when describe_stack with invalid stack name
          # "1 validation error detected: Value 'instance_and_route53' at 'stackName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/._+]*"
          puts "Invalid stack name: #{stack_name}"
          puts "Full error message: #{e.message}"
          exit 1
        else
          raise # re-raise exception  because unsure what other errors can happen
        end
      end
      exist
    end

    def find_stack(stack_name)
      resp = cfn.describe_stacks(stack_name: stack_name)
      resp.stacks.first
    rescue Aws::CloudFormation::Errors::ValidationError => e
      # example: Stack with id demo-web does not exist
      if e.message =~ /Stack with/ && e.message =~ /does not exist/
        nil
      else
        raise
      end
    end

    def rollback_complete?(stack)
      stack.stack_status == 'ROLLBACK_COMPLETE'
    end

    def testing_update?
      # TODO: Figure out how to get rid of this
      ENV['TEST'] #  && self.class.name == "BoltCfn::Update"
    end
  end
end

Version data entries

37 entries across 37 versions & 4 rubygems

Version Path
pipedream-0.4.8 vendor/cfn-status/lib/cfn/aws_service.rb
pipedream-0.4.7 vendor/cfn-status/lib/cfn/aws_service.rb
pipedream-0.4.6 vendor/cfn-status/lib/cfn/aws_service.rb
pipedream-0.4.5 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.8 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.7 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.6 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.5 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.4 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.3 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.2 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.1 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.9.0 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.8.6 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.8.5 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.8.4 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.8.3 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.8.2 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.8.1 vendor/cfn-status/lib/cfn/aws_service.rb
cody-0.8.0 vendor/cfn-status/lib/cfn/aws_service.rb