Class: AwsHelpers::CloudFormation::UploadTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_helpers/cloud_formation/upload_template.rb

Instance Method Summary collapse

Constructor Details

#initialize(s3_client, stack_name, template, bucket_name, bucket_encrypt) ⇒ UploadTemplate


5
6
7
8
9
10
11
# File 'lib/aws_helpers/cloud_formation/upload_template.rb', line 5

def initialize(s3_client, stack_name, template, bucket_name, bucket_encrypt)
  @s3_client = s3_client
  @stack_name = stack_name
  @template = template
  @bucket_name = bucket_name
  @bucket_encrypt = bucket_encrypt
end

Instance Method Details

#executeObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/aws_helpers/cloud_formation/upload_template.rb', line 13

def execute
  if s3_template?
    puts "Uploading #{@stack_name} to S3 bucket #{@bucket_name} "
    request = {
      bucket: @bucket_name,
      key: @stack_name,
      body: @template,
    }
    request.merge!(server_side_encryption: 'AES256') if @bucket_encrypt
    @s3_client.put_object(
      request
    )
    "https://s3-#{s3_location}.amazonaws.com/#{@bucket_name}/#{@stack_name}"
  end
end

#s3_locationObject


29
30
31
32
33
34
# File 'lib/aws_helpers/cloud_formation/upload_template.rb', line 29

def s3_location
  resp = @s3_client.get_bucket_location(
    bucket: @bucket_name,
  )
  resp[:location_constraint]
end

#s3_template?Boolean


36
37
38
# File 'lib/aws_helpers/cloud_formation/upload_template.rb', line 36

def s3_template?
  !@bucket_name.nil?
end