Module: Jets::AwsServices::StackStatus
- Included in:
- Jets::AwsServices
- Defined in:
- lib/jets/aws_services/stack_status.rb
Constant Summary collapse
- @@stack_exists_cache =
Only cache if it is true because the initial deploy checks live status until a stack exists.
[]
Instance Method Summary collapse
- #output_value(outputs, key) ⇒ Object
-
#stack_exists?(stack_name) ⇒ Boolean
helps with CloudFormation rate limit.
Instance Method Details
#output_value(outputs, key) ⇒ Object
33 34 35 36 |
# File 'lib/jets/aws_services/stack_status.rb', line 33 def output_value(outputs, key) out = outputs.find { |o| o.output_key == key } out&.output_value end |
#stack_exists?(stack_name) ⇒ Boolean
helps with CloudFormation rate limit
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jets/aws_services/stack_status.rb', line 5 def stack_exists?(stack_name) return false if Jets.env.test? return true if ENV["JETS_NO_INTERNET"] return true if @@stack_exists_cache.include?(stack_name) 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 cfn.describe_stacks(stack_name: stack_name) @@stack_exists_cache << stack_name exist = true rescue Aws::CloudFormation::Errors::ValidationError => e if /does not exist/.match?(e.) 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:/._+]*" log.info "Invalid stack name: #{stack_name}" log.info "Full error message: #{e.}" exit 1 else raise # re-raise exception because unsure what other errors can happen end end exist end |