class AwsStack::CfnTemplate
AWS CFN template file handling
Attributes
body[R]
url[R]
Public Class Methods
new(options)
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 7 def initialize(options) @credentials = options[:credentials] @templatefile = options[:templatefile] @stackname = options[:stackname] @bucket_name = 'awsstack.cloudformation.templates' @bucket_template_filename = "#{@stackname}_#{File.basename(@templatefile)}" template end
Public Instance Methods
delete_template()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 16 def delete_template s3.delete_object( bucket: @bucket_name, key: @bucket_template_filename ) end
Private Instance Methods
bucket_exist?()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 62 def bucket_exist? s3.head_bucket( bucket: @bucket_name ) true rescue Aws::S3::Errors::NotFound # , Aws::S3::Errors::Http301Error false end
create_bucket()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 56 def create_bucket s3.create_bucket( bucket: @bucket_name ) end
put_template()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 48 def put_template s3.put_object( bucket: @bucket_name, key: @bucket_template_filename, body: template_file_body ) end
s3()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 71 def s3 @s3 || @s3 = Aws::S3::Client.new(credentials: @credentials) end
template()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 25 def template case File.size? @templatefile when nil, 0 raise "Template file : '#{@templatefile}', not found or zero length." when 1..51_200 @body = template_file_body when 51_201..460_800 @url = template_url else raise "Template file : '#{@templatefile}', Too large. (> 460.800 bytes)" end end
template_file_body()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 38 def template_file_body File.open(@templatefile, 'r').read end
template_url()
click to toggle source
# File lib/awsstack/cfntemplate.rb, line 42 def template_url create_bucket unless bucket_exist? put_template "https://s3.amazonaws.com/#{@bucket_name}/#{@bucket_template_filename}" end