Class: LambdaWrap::S3BucketManager

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda_wrap/s3_bucket_manager.rb

Overview

The S3BucketManager would have functions to help add policies, CORS etc to S3 bucket.

Instance Method Summary collapse

Constructor Details

#initializeS3BucketManager

The constructor creates an instance of s3 bucket

  • Validating basic AWS configuration

  • Creating the underlying client to interact with the AWS SDK.

  • Defining the temporary path of the api-gateway-importer jar file



12
13
14
# File 'lib/lambda_wrap/s3_bucket_manager.rb', line 12

def initialize
  @s3bucket = Aws::S3::Client.new()
end

Instance Method Details

#setup_policy(s3_bucket_name, policy) ⇒ Object

Adds policy to the bucket

Arguments [s3_bucket_name] S3 bucket name. [policy] Policy to be added to the bucket



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lambda_wrap/s3_bucket_manager.rb', line 22

def setup_policy(s3_bucket_name, policy)
  # Validate the parameters
  raise "S3 bucket is not provided" unless s3_bucket_name
  raise "Policy json is not provided" unless policy

  @s3bucket.put_bucket_policy({
    bucket: s3_bucket_name,
    policy: policy.to_json
  })
  puts "Created/Updated policy: #{policy} in S3 bucket #{s3_bucket_name}"
end