Creates a stack as specified in the template. After the call completes successfully, the stack
creation starts. You can check the status of the stack via the DescribeStacks
API.
Currently, the limit for stacks is 20 stacks per account per region.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
---|---|---|---|
|
Required |
The name associated with the stack. The name must be unique within your AWS account. Must contain only alphanumeric characters (case sensitive) and start with an alpha character. Maximum length of the name is 255 characters. |
|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
---|---|
A |
Examples
Create a new stack using a remote template.
CloudFormation can access stack templates from public URLs.
$stack = new AmazonCloudFormation(); $response = $stack->create_stack('my-stack', array( 'TemplateURL' => 'http://cloudformation-us-east-1.s3.amazonaws.com/cloudformation.json' )); // Success? var_dump($response->isOK());Result:
bool(true)
Create a new stack using a JSON template.
Use a JSON string to define a stack template, then pass it to create_stack()
.
$stack = new AmazonCloudFormation(); $template = CFStackTemplate::json('{ "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { "MyGroup" : { "Type" : "AWS::AutoScaling::AutoScalingGroup", "Properties" : { "AvailabilityZones" : [ "us-east-1a" ], "LaunchConfigurationName" : { "Ref" : "SimpleConfig" }, "MinSize" : "1", "MaxSize" : "3", "LoadBalancerNames" : [ { "Ref" : "MyLoadBalancer" } ] } }, "MyLoadBalancer" : { "Type" : "AWS::ElasticLoadBalancing::LoadBalancer", "Properties" : { "AvailabilityZones" : [ "us-east-1a" ], "Listeners" : [ { "LoadBalancerPort" : "80", "InstancePort" : "80", "Protocol" : "HTTP" } ] } }, "SimpleConfig" : { "Type" : "AWS::AutoScaling::LaunchConfiguration", "Properties" : { "ImageId" : "ami-20b65349", "SecurityGroups" : [ { "Ref" : "OpenPorts" } ], "InstanceType" : "m1.small" } }, "OpenPorts" : { "Type" : "AWS::EC2::SecurityGroup", "Properties" : { "GroupDescription" : "open port 80", "SecurityGroupIngress" : [ { "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0" } ] } }, "MyTrigger" : { "Type" : "AWS::AutoScaling::Trigger", "Properties" : { "MetricName" : "CPUUtilization", "Namespace" : "AWS/EC2", "Statistic" : "Average", "Period" : "300", "UpperBreachScaleIncrement" : "1", "LowerBreachScaleIncrement" : "-1", "AutoScalingGroupName" : { "Ref" : "MyGroup" }, "BreachDuration" : "600", "UpperThreshold" : "90", "LowerThreshold" : "75", "Dimensions" : [ { "Name" : "AutoScalingGroupName", "Value" : { "Ref" : "MyGroup" } } ] } } }, "Outputs" : { "URL" : { "Value" : { "Ref" : "MyLoadBalancer" } } } }'); $response = $stack->create_stack('my-stack', array( 'TemplateBody' => $template )); // Success? var_dump($response->isOK());Result:
bool(true)
Create a new stack using an associative array (map) template.
Use a multi-dimensional array to define a stack template, then pass it to create_stack()
.
$stack = new AmazonCloudFormation(); $template = CFStackTemplate::map(array( 'AWSTemplateFormatVersion' => '2010-09-09', 'Resources' => array( 'MyGroup' => array( 'Type' => 'AWS::AutoScaling::AutoScalingGroup', 'Properties' => array( 'AvailabilityZones' => array( 'us-east-1a' ), 'LaunchConfigurationName' => array( 'Ref' => 'SimpleConfig' ), 'MinSize' => '1', 'MaxSize' => '3', 'LoadBalancerNames' => array( array( 'Ref' => 'MyLoadBalancer' ) ) ) ), 'MyLoadBalancer' => array( 'Type' => 'AWS::ElasticLoadBalancing::LoadBalancer', 'Properties' => array( 'AvailabilityZones' => array( 'us-east-1a' ), 'Listeners' => array( array( 'LoadBalancerPort' => '80', 'InstancePort' => '80', 'Protocol' => 'HTTP' ) ) ) ), 'SimpleConfig' => array( 'Type' => 'AWS::AutoScaling::LaunchConfiguration', 'Properties' => array( 'ImageId' => 'ami-20b65349', 'SecurityGroups' => array( array( 'Ref' => 'OpenPorts' ) ), 'InstanceType' => 'm1.small' ) ), 'OpenPorts' => array( 'Type' => 'AWS::EC2::SecurityGroup', 'Properties' => array( 'GroupDescription' => 'open port 80', 'SecurityGroupIngress' => array( array( 'IpProtocol' => 'tcp', 'FromPort' => '80', 'ToPort' => '80', 'CidrIp' => '0.0.0.0/0' ) ) ) ), 'MyTrigger' => array( 'Type' => 'AWS::AutoScaling::Trigger', 'Properties' => array( 'MetricName' => 'CPUUtilization', 'Namespace' => 'AWS/EC2', 'Statistic' => 'Average', 'Period' => '300', 'UpperBreachScaleIncrement' => '1', 'LowerBreachScaleIncrement' => '-1', 'AutoScalingGroupName' => array( 'Ref' => 'MyGroup' ), 'BreachDuration' => '600', 'UpperThreshold' => '90', 'LowerThreshold' => '75', 'Dimensions' => array( array( 'Name' => 'AutoScalingGroupName', 'Value' => array( 'Ref' => 'MyGroup' ) ) ) ) ) ), 'Outputs' => array( 'URL' => array( 'Value' => array( 'Ref' => 'MyLoadBalancer' ) ) ) )); $response = $stack->create_stack('my-stack', array( 'TemplateBody' => $template )); // Success? var_dump($response->isOK());Result:
bool(true)
Create a new stack using a remote template. Also set other optional parameters.
Uses a Notification ARN.
$stack = new AmazonCloudFormation(); $response = $stack->create_stack('my-stack', array( 'TemplateURL' => 'https://s3.amazonaws.com/cloudformation-templates/CloudFormationSample_Instance.template', 'NotificationARNs' => 'arn:aws:sns:us-east-1:0123456789012:my-topic', 'Parameters' => array( array( 'ParameterKey' => 'KeyPair', 'ParameterValue' => 'my-keypair' ) ), 'DisableRollback' => 'false', 'TimeoutInMinutes' => 15 )); // Success? var_dump($response->isOK());Result:
bool(true)
Related Methods
Source
Method defined in services/cloudformation.class.php | Toggle source view (43 lines) | View on GitHub