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-4.0.12 lib/jets/aws_services/s3_bucket.rb
jets-4.0.11 lib/jets/aws_services/s3_bucket.rb
jets-5.0.13 lib/jets/aws_services/s3_bucket.rb
jets-5.0.12 lib/jets/aws_services/s3_bucket.rb
jets-5.0.11 lib/jets/aws_services/s3_bucket.rb
jets-5.0.10 lib/jets/aws_services/s3_bucket.rb
jets-5.0.9 lib/jets/aws_services/s3_bucket.rb
jets-5.0.8 lib/jets/aws_services/s3_bucket.rb
jets-5.0.7 lib/jets/aws_services/s3_bucket.rb
jets-5.0.6 lib/jets/aws_services/s3_bucket.rb
jets-5.0.5 lib/jets/aws_services/s3_bucket.rb
jets-5.0.4 lib/jets/aws_services/s3_bucket.rb
jets-5.0.3 lib/jets/aws_services/s3_bucket.rb
jets-5.0.2 lib/jets/aws_services/s3_bucket.rb
jets-5.0.1 lib/jets/aws_services/s3_bucket.rb
jets-5.0.0 lib/jets/aws_services/s3_bucket.rb
jets-4.0.10 lib/jets/aws_services/s3_bucket.rb
jets-5.0.0.beta1 lib/jets/aws_services/s3_bucket.rb
jets-4.0.9 lib/jets/aws_services/s3_bucket.rb
jets-4.0.8 lib/jets/aws_services/s3_bucket.rb