Class: AWS::CloudFormation::StackCollection

Inherits:
Object
  • Object
show all
Includes:
AWS::Core::Collection::Simple
Defined in:
lib/aws/cloud_formation/stack_collection.rb

Instance Method Summary collapse

Methods included from AWS::Core::Collection

#each, #each_batch, #enum, #first, #in_groups_of, #page

Instance Method Details

#[](stack_name) ⇒ Object



152
153
154
# File 'lib/aws/cloud_formation/stack_collection.rb', line 152

def [] stack_name
  Stack.new(stack_name, :config => config)
end

#create(stack_name, template, options = {}) ⇒ Stack

Creates a new stack.

Examples:

Creating a stack with a template string.


template = " {\n   \"AWSTemplateFormatVersion\" : \"2010-09-09\",\n   \"Description\": \"A simple template\",\n   \"Resources\": {\n     \"web\": {\n       \"Type\": \"AWS::EC2::Instance\",\n       \"Properties\": {\n         \"ImageId\": \"ami-41814f28\"\n       }\n     }\n   }\n}\n"
stack = cfm.stacks.create('stack-name', template)

Creating a stack from an S3 object.


template = AWS::S3.new.buckets['templates'].objects['template-1']
stack = cfm.stacks.create('stack-name', template)

Creating a stack with 3 parameters.


template = "{\n  \"AWSTemplateFormatVersion\" : \"2010-09-09\",\n  \"Description\": \"A simple template\",\n  \"Parameters\" : {\n    \"KeyName\" : {\n      \"Description\" : \"Name of a KeyPair to use with SSH.\",\n      \"Type\" : \"String\"\n    },\n    \"SecurityGroup\" : {\n      \"Description\" : \"The security group to launch in.\",\n      \"Type\" : \"String\"\n    },\n    \"InstanceType\" : {\n      \"Description\" : \"The size of instance to launch.\",\n      \"Type\" : \"String\"\n    }\n  },\n  \"Resources\": {\n    \"web\": {\n      \"Type\": \"AWS::EC2::Instance\",\n      \"Properties\": {\n        \"InstanceType\": { \"Ref\" : \"InstanceType\" },\n        \"SecurityGroups\" : [ {\"Ref\" : \"SecurityGroup\"} ],\n        \"KeyName\": { \"Ref\" : \"KeyName\" },\n        \"ImageId\": \"ami-41814f28\"\n      }\n    }\n  }\n}\n"

stack = cfm.stacks.create('name', template, :parameters => {
  'KeyName' => 'key-pair-name',
  'SecurityGroup' => 'security-group-name',
  'InstanceType' => 'm1.large',
})

Parameters:

  • stack_name (String)
  • template (String, URI, S3::S3Object, Object)

    The stack template. This may be provided in a number of formats including:

    • a String, containing the template as a JSON document.

    • a URL String pointing to the document in S3.

    • a URI object pointing to the document in S3.

    • an S3::S3Object which contains the template.

    • an Object which responds to #to_json and returns the template.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :capabilities (Array<String>)

    The list of capabilities that you want to allow in the stack. If your stack contains IAM resources, you must specify the CAPABILITY_IAM value for this parameter; otherwise, this action returns an InsufficientCapabilities error. IAM resources are the following:

    • AWS::IAM::AccessKey

    • AWS::IAM::Group

    • AWS::IAM::Policy

    • AWS::IAM::User

    • AWS::IAM::UserToGroupAddition

  • :disable_rollback (Boolean) — default: false

    Set to true to disable rollback on stack creation failures.

  • :notify (Object)

    One or more SNS topics ARN string or SNS::Topic objects. This param may be passed as a single value or as an array. CloudFormation will publish stack related events to these topics.

  • :parameters (Hash)

    A hash that specifies the input parameters of the new stack.

  • :timeout (Integer)

    The number of minutes that may pass before the stack creation fails. If :disable_rollback is false, the stack will be rolled back.

Returns:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/aws/cloud_formation/stack_collection.rb', line 134

def create stack_name, template, options = {}

  client_opts = options.dup
  client_opts[:template] = template

  apply_stack_name(stack_name, client_opts)
  apply_template(client_opts)
  apply_disable_rollback(client_opts)
  apply_notification_arns(client_opts)
  apply_parameters(client_opts)
  apply_timeout(client_opts)

  resp = client.create_stack(client_opts)

  Stack.new(stack_name, :config => config, :stack_id => resp.stack_id)

end

#with_status(status_filter) ⇒ StackCollection

Limits the stacks that are enumerated.

cloud_formation.stacks.with_status(:create_complete).each do |stack|
  puts stack.name
end

Parameters:

  • status_filter (Symbol, String)

    A status to filter stacks with. Valid values include:

    • :create_in_progress

    • :create_failed

    • :create_complete

    • :rollback_in_progress

    • :rollback_failed

    • :rollback_complete

    • :delete_in_progress

    • :delete_failed

    • :delete_complete

    • :update_in_progress

    • :update_complete_cleanup_in_progress

    • :update_complete

    • :update_rollback_in_progress

    • :update_rollback_failed

    • :update_rollback_complete_cleanup_in_progress

    • :update_rollback_complete

Returns:

  • (StackCollection)

    Returns a new stack collection that filters the stacks returned by the given status.



184
185
186
# File 'lib/aws/cloud_formation/stack_collection.rb', line 184

def with_status status_filter
  StackCollection.new(:status_filter => status_filter, :config => config)
end