Validates a specified template.
Access
public
Parameters
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
Optional |
An associative array of parameters that can have the following keys:
|
Returns
Type |
Description |
|---|---|
|
A |
Examples
Validate a remote template.
CloudFormation can access stack templates from public URLs.
$stack = new AmazonCloudFormation(); $response = $stack->validate_template(array( 'TemplateURL' => 'https://s3.amazonaws.com/cloudformation-templates-us-east-1/AWSCloudFormer.template' )); // Success? var_dump($response->isOK());Result:
bool(true)
Validate a JSON template.
Use a JSON string to define a stack template, then pass it to validate_template().
$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->validate_template(array(
'TemplateBody' => $template
));
// Success?
var_dump($response->isOK());
Result:
bool(true)
Validate an associative array (map) template.
Use a multi-dimensional array to define a stack template, then pass it to validate_template().
$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->validate_template(array( 'TemplateBody' => $template )); // Success? var_dump($response->isOK());Result:
bool(true)
Related Methods
Source
Method defined in services/cloudformation.class.php | Toggle source view (6 lines) | View on GitHub

