json ( $template )

Removes whitespace from a JSON template.

Access

public static

Parameters

Parameter

Type

Required

Description

$template

string

Required

A JSON representation of the stack template. Must have strict JSON-specific formatting.

Returns

Type

Description

string

A JSON representation of the template.

Examples

Handle JSON version of the template.

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

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback