Sha256: ebadebdcd3f41cc219da2323032dcafc03569f30a6ceee58865ce6d33e773f55
Contents?: true
Size: 840 Bytes
Versions: 138
Compression:
Stored size: 840 Bytes
Contents
module Jets::AwsServices class S3Bucket include Jets::AwsServices def self.ensure_exists(bucket_name) new(bucket_name).ensure_exists end def initialize(name) @name = name end def ensure_exists s3.create_bucket(bucket: @name) unless exists? rescue Aws::S3::Errors::BucketAlreadyExists => e puts "ERROR #{e.class}: #{e.message}".color(:red) puts "Bucket name: #{@name}" exit 1 end def exists? begin s3.head_bucket(bucket: @name) true rescue Aws::S3::Errors::BucketAlreadyOwnedByYou, Aws::S3::Errors::Http301Error => e # These exceptions indicate bucket already exists # Aws::S3::Errors::Http301Error could be inaccurate but compromising for simplicity true rescue false end end end end
Version data entries
138 entries across 138 versions & 3 rubygems