lib/jets/commands/delete.rb in jets-0.8.0 vs lib/jets/commands/delete.rb in jets-0.8.1
- old
+ new
@@ -72,17 +72,29 @@
end
end
def s3_bucket_name
return @s3_bucket_name if defined?(@s3_bucket_name)
+ return unless bucket_exists?
resp = cfn.describe_stacks(stack_name: parent_stack_name)
outputs = resp.stacks[0].outputs
if outputs.empty?
@s3_bucket_name = false
else
@s3_bucket_name = outputs.find {|o| o.output_key == 'S3Bucket'}.output_value
end
+ end
+
+ # Thanks: https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-example-does-bucket-exist.html
+ def bucket_exists?
+ bucket_exists = false
+ begin
+ resp = s3.head_bucket(bucket: @s3_bucket_name, use_accelerate_endpoint: false)
+ bucket_exists = true
+ rescue
+ end
+ bucket_exists
end
def parent_stack_name
Jets::Naming.parent_stack_name
end