map ( $template )

Converts an associative array (map) of the template into a JSON string.

Access

public static

Parameters

Parameter

Type

Required

Description

$template

array

Required

An associative array that maps directly to its JSON counterpart.

Returns

Type

Description

string

A JSON representation of the template.

Examples

Handle associative array (map) version of the template.

$template = CFStackTemplate::map(array(
	'AWSTemplateFormatVersion' => '2010-09-09',
	'Description' => 'Create an EC2 instance running the Amazon Linux 32 bit AMI.',
	'Parameters' => array(
		'KeyPair' => array(
			'Description' => 'The EC2 Key Pair to allow SSH access to the instance',
			'Type' => 'String'
		)
	),
	'Mappings' => array(
		'RegionMap' => array(
			'us-east-1' => array( 'AMI' => 'ami-76f0061f' ),
			'us-west-1' => array( 'AMI' => 'ami-655a0a20' ),
			'eu-west-1' => array(	'AMI' => 'ami-7fd4e10b' ),
			'ap-southeast-1' => array( 'AMI' => 'ami-72621c20' )
		)
	),
	'Resources' => array(
		'Ec2Instance' => array(
			'Type' => 'AWS::EC2::Instance',
			'Properties' => array(
				'KeyName' => array( 'Ref' => 'KeyPair' ),
				'ImageId' => array( 'Fn::FindInMap' => array( 'RegionMap', array( 'Ref' => 'AWS::Region' ), 'AMI' ))
			)
		)
	),
	'Outputs' => array(
		'InstanceId' => array(
			'Description' => 'The InstanceId of the newly created EC2 instance',
			'Value' => array( 'Ref' => 'Ec2Instance' )
		),
		'AZ' => array(
			'Description' => 'The Availability Zone of the newly created EC2 instance',
			'Value' => array( 'Fn::GetAtt' => array( 'Ec2Instance', 'AvailabilityZone' ) )
		),
		'PublicIP' => array(
			'Description' => 'The Public IP address of the newly created EC2 instance',
			'Value' => array( 'Fn::GetAtt' => array( 'Ec2Instance', 'PublicIp' ) )
		)
	)
));

var_dump(sha1($template));
Result:
string(40) "9424c0db71fca8b6e0200d77571e41bb867d7f4b"

Related Methods

Source

Method defined in utilities/stacktemplate.class.php | Toggle source view (4 lines) | View on GitHub

public static function map($template)
{
    return json_encode($template);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback