validate_template ( $opt )

Validates a specified template.

Access

public

Parameters

Parameter

Type

Required

Description

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • TemplateBody - string - Optional - String containing the template body. (For more information, go to the AWS CloudFormation User Guide.) Conditional: You must pass TemplateURL or TemplateBody. If both are passed, only TemplateBody is used.
  • TemplateURL - string - Optional - Location of file containing the template body. The URL must point to a template (max size: 307,200 bytes) located in an S3 bucket in the same region as the stack. For more information, go to the AWS CloudFormation User Guide. Conditional: You must pass TemplateURL or TemplateBody. If both are passed, only TemplateBody is used.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

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

public function validate_template($opt = null)
{
    if (!$opt) $opt = array();
            
    return $this->authenticate('ValidateTemplate', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback