Module: Lono::Cfn::AwsService
- Defined in:
- lib/lono/cfn/aws_service.rb
Instance Method Summary collapse
- #cfn ⇒ Object
- #find_stack(stack_name) ⇒ Object
- #rollback_complete?(stack) ⇒ Boolean
- #stack_exists?(stack_name) ⇒ Boolean
- #testing_update? ⇒ Boolean
Instance Method Details
#cfn ⇒ Object
4 5 6 |
# File 'lib/lono/cfn/aws_service.rb', line 4 def cfn @cfn ||= Aws::CloudFormation::Client.new end |
#find_stack(stack_name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lono/cfn/aws_service.rb', line 34 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. =~ /Stack with/ && e. =~ /does not exist/ nil else raise end end |
#rollback_complete?(stack) ⇒ Boolean
46 47 48 |
# File 'lib/lono/cfn/aws_service.rb', line 46 def rollback_complete?(stack) stack.stack_status == 'ROLLBACK_COMPLETE' end |
#stack_exists?(stack_name) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lono/cfn/aws_service.rb', line 8 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. =~ /does not exist/ exist = false elsif e..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.}" exit 1 else raise # re-raise exception because unsure what other errors can happen end end exist end |
#testing_update? ⇒ Boolean
50 51 52 |
# File 'lib/lono/cfn/aws_service.rb', line 50 def testing_update? ENV['TEST'] && self.class.name == "LonoCfn::Update" end |