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

Version Path
jets-3.0.2 lib/jets/aws_services/s3_bucket.rb
jets-3.0.1 lib/jets/aws_services/s3_bucket.rb
jets-3.0.0 lib/jets/aws_services/s3_bucket.rb
jets-2.3.18 lib/jets/aws_services/s3_bucket.rb
jets-2.3.17 lib/jets/aws_services/s3_bucket.rb
jets-2.3.16 lib/jets/aws_services/s3_bucket.rb
jets-2.3.15 lib/jets/aws_services/s3_bucket.rb
jets-2.3.14 lib/jets/aws_services/s3_bucket.rb
jets-2.3.13 lib/jets/aws_services/s3_bucket.rb
jets-2.3.12 lib/jets/aws_services/s3_bucket.rb
jets-2.3.11 lib/jets/aws_services/s3_bucket.rb
jets-2.3.10 lib/jets/aws_services/s3_bucket.rb
jets-2.3.9 lib/jets/aws_services/s3_bucket.rb
jets-2.3.8 lib/jets/aws_services/s3_bucket.rb
jets-2.3.7 lib/jets/aws_services/s3_bucket.rb
jets-2.3.6 lib/jets/aws_services/s3_bucket.rb
jets-2.3.5 lib/jets/aws_services/s3_bucket.rb
jets-2.3.4 lib/jets/aws_services/s3_bucket.rb
jets-2.3.3 lib/jets/aws_services/s3_bucket.rb
jets-2.3.2 lib/jets/aws_services/s3_bucket.rb