Class: CloudFormationWrapper::StackManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudformation_wrapper/stack_manager.rb

Overview

Stack Manager Class Class containing static convenience methods for deploying and managing CloudFormation Stacks.

Since:

  • 1.0

Class Method Summary collapse

Class Method Details

.deploy(options) ⇒ Object

Since:

  • 1.0



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cloudformation_wrapper/stack_manager.rb', line 6

def self.deploy(options)
  unless options[:client]
    access_key_id = options[:access_key_id] || ENV['AWS_ACCESS_KEY_ID'] || ENV['ACCESS_KEY'] ||
                    raise(ArgumentError, 'Cannot find AWS Access Key ID.')

    secret_access_key = options[:secret_access_key] || ENV['AWS_SECRET_ACCESS_KEY'] || ENV['SECRET_KEY'] ||
                        raise(ArgumentError, 'Cannot find AWS Secret Key.')

    credentials = Aws::Credentials.new(access_key_id, secret_access_key)
  end

  region = options[:region] || ENV['AWS_REGION'] || ENV['AMAZON_REGION'] || ENV['AWS_DEFAULT_REGION'] ||
           raise(ArgumentError, 'Cannot find AWS Region.')

  verified_options = verify_options(options)

  cf_client = verified_options[:client] || Aws::CloudFormation::Client.new(credentials: credentials, region: region)

  ensure_template_file_exists(verified_options[:template_path], cf_client)

  deploy_stack(
    verified_options[:parameters],
    verified_options[:name],
    verified_options[:template_path],
    verified_options[:wait_for_stack],
    cf_client
  )
end