GetTemplate - Amazon CloudFormation
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

GetTemplate

Returns the template body for a specified stack. You can get the template for running or deleted stacks.

For deleted stacks, GetTemplate returns the template for up to 90 days after the stack has been deleted.

Note

If the template doesn't exist, a ValidationError is returned.

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

ChangeSetName

The name or Amazon Resource Name (ARN) of a change set for which Amazon CloudFormation returns the associated template. If you specify a name, you must also specify the StackName.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1600.

Pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/]*

Required: No

StackName

The name or the unique stack ID that's associated with the stack, which aren't always interchangeable:

  • Running stacks: You can specify either the stack's name or its unique stack ID.

  • Deleted stacks: You must specify the unique stack ID.

Default: There is no default value.

Type: String

Required: No

TemplateStage

For templates that include transforms, the stage of the template that Amazon CloudFormation returns. To get the user-submitted template, specify Original. To get the template after Amazon CloudFormation has processed all transforms, specify Processed.

If the template doesn't include transforms, Original and Processed return the same template. By default, Amazon CloudFormation specifies Processed.

Type: String

Valid Values: Original | Processed

Required: No

Response Elements

The following elements are returned by the service.

StagesAvailable.member.N

The stage of the template that you can retrieve. For stacks, the Original and Processed templates are always available. For change sets, the Original template is always available. After Amazon CloudFormation finishes creating the change set, the Processed template becomes available.

Type: Array of strings

Valid Values: Original | Processed

TemplateBody

Structure containing the template body. (For more information, go to Template Anatomy in the Amazon CloudFormation User Guide.)

Amazon CloudFormation returns the same template that was used when the stack was created.

Type: String

Length Constraints: Minimum length of 1.

Errors

For information about the errors that are common to all actions, see Common Errors.

ChangeSetNotFound

The specified change set name or ID doesn't exit. To view valid change sets for a stack, use the ListChangeSets operation.

HTTP Status Code: 404

Examples

GetTemplate

This example illustrates one usage of GetTemplate.

Sample Request

https://cloudformation.us-east-1.amazonaws.com/ ?Action=GetTemplate &StackName=MyStack &Version=2010-05-15 &SignatureVersion=2 &Timestamp=2010-07-27T22%3A26%3A28.000Z &AWSAccessKeyId=[AWS Access KeyID] &Signature=[Signature]

Sample Response

<GetTemplateResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/"> <GetTemplateResult> <TemplateBody>"{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Simple example", "Resources" : { "MySQS" : { "Type" : "AWS::SQS::Queue", "Properties" : { } } } }</TemplateBody> </GetTemplateResult> <ResponseMetadata> <RequestId>b9b4b068-3a41-11e5-94eb-example</RequestId> </ResponseMetadata> </GetTemplateResponse>

See Also

For more information about using this API in one of the language-specific Amazon SDKs, see the following: