Sha256: f141add1234cdbc58aa187c3abc1d087e1fb3e0f8ed82a1772be8beeb5b7ce1f

Contents?: true

Size: 934 Bytes

Versions: 6

Compression:

Stored size: 934 Bytes

Contents

require 'aws-sdk-s3'

Aws.use_bundled_cert!

module TerraformDevKit
  module Aws
    class S3
      def initialize(credentials, region)
        @s3_client = ::Aws::S3::Client.new(
          credentials: credentials,
          region: region
        )
      end

      def create_bucket(bucket_name)
        @s3_client.create_bucket(
          bucket: bucket_name
        )
      end

      def delete_bucket(bucket_name)
        empty_bucket(bucket_name)

        @s3_client.delete_bucket(
          bucket: bucket_name
        )
      end

      def empty_bucket(bucket_name)
        keys_to_delete = @s3_client
                        .list_objects_v2(bucket: bucket_name)
                        .contents
                        .map { |x| { key: x.key } }

        @s3_client.delete_objects(
          bucket: bucket_name,
          delete: {
            objects: keys_to_delete
          }
        )
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
TerraformDevKit-0.4.0 lib/TerraformDevKit/aws/s3.rb
TerraformDevKit-0.3.7 lib/TerraformDevKit/aws/s3.rb
TerraformDevKit-0.3.6 lib/TerraformDevKit/aws/s3.rb
TerraformDevKit-0.3.5 lib/TerraformDevKit/aws/s3.rb
TerraformDevKit-0.3.4 lib/TerraformDevKit/aws/s3.rb
TerraformDevKit-0.3.2 lib/TerraformDevKit/aws/s3.rb