class Template
| Language | Type name | 
|---|---|
|  .NET | Amazon.CDK.Assertions.Template | 
|  Java | software.amazon.awscdk.assertions.Template | 
|  Python | aws_cdk.assertions.Template | 
|  TypeScript (source) | @aws-cdk/assertions»Template | 
Suite of assertions that can be run on a CDK stack.
Typically used, as part of unit tests, to validate that the rendered CloudFormation template has expected resources and properties.
Example
import { Stack } from '@aws-cdk/core';
import { Template } from '@aws-cdk/assertions';
const stack = new Stack(/* ... */);
// ...
const template = Template.fromStack(stack);
Methods
| Name | Description | 
|---|---|
| find | Get the set of matching Conditions that match the given properties in the CloudFormation template. | 
| find | Get the set of matching Mappings that match the given properties in the CloudFormation template. | 
| find | Get the set of matching Outputs that match the given properties in the CloudFormation template. | 
| find | Get the set of matching Parameters that match the given properties in the CloudFormation template. | 
| find | Get the set of matching resources of a given type and properties in the CloudFormation template. | 
| has | Assert that a Condition with the given properties exists in the CloudFormation template. | 
| has | Assert that a Mapping with the given properties exists in the CloudFormation template. | 
| has | Assert that an Output with the given properties exists in the CloudFormation template. | 
| has | Assert that a Parameter with the given properties exists in the CloudFormation template. | 
| has | Assert that a resource of the given type and given definition exists in the CloudFormation template. | 
| has | Assert that a resource of the given type and properties exists in the CloudFormation template. | 
| resource | Assert that the given number of resources of the given type exist in the template. | 
| template | Assert that the CloudFormation template matches the given value. | 
| to | The CloudFormation template deserialized into an object. | 
| static from | Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object. | 
| static from | Base your assertions on the CloudFormation template synthesized by a CDK Stack. | 
| static from | Base your assertions from an existing CloudFormation template formatted as a JSON string. | 
findConditions(logicalId, props?) 
public findConditions(logicalId: string, props?: any): { [string]: { [string]: any } }
Parameters
- logicalId string— the name of the condition.
- props any— by default, matches all Conditions in the template.
Returns
- { [string]: { [string]: any } }
Get the set of matching Conditions that match the given properties in the CloudFormation template.
findMappings(logicalId, props?) 
public findMappings(logicalId: string, props?: any): { [string]: { [string]: any } }
Parameters
- logicalId string— the name of the mapping.
- props any— by default, matches all Mappings in the template.
Returns
- { [string]: { [string]: any } }
Get the set of matching Mappings that match the given properties in the CloudFormation template.
findOutputs(logicalId, props?) 
public findOutputs(logicalId: string, props?: any): { [string]: { [string]: any } }
Parameters
- logicalId string— the name of the output.
- props any— by default, matches all Outputs in the template.
Returns
- { [string]: { [string]: any } }
Get the set of matching Outputs that match the given properties in the CloudFormation template.
findParameters(logicalId, props?) 
public findParameters(logicalId: string, props?: any): { [string]: { [string]: any } }
Parameters
- logicalId string— the name of the parameter.
- props any— by default, matches all Parameters in the template.
Returns
- { [string]: { [string]: any } }
Get the set of matching Parameters that match the given properties in the CloudFormation template.
findResources(type, props?) 
public findResources(type: string, props?: any): { [string]: { [string]: any } }
Parameters
- type string— the type to match in the CloudFormation template.
- props any— by default, matches all resources with the given type.
Returns
- { [string]: { [string]: any } }
Get the set of matching resources of a given type and properties in the CloudFormation template.
hasCondition(logicalId, props) 
public hasCondition(logicalId: string, props: any): void
Parameters
- logicalId string— the name of the mapping.
- props any— the output as should be expected in the template.
Assert that a Condition with the given properties exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavour, use other matchers in the Match class.
hasMapping(logicalId, props) 
public hasMapping(logicalId: string, props: any): void
Parameters
- logicalId string— the name of the mapping.
- props any— the output as should be expected in the template.
Assert that a Mapping with the given properties exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavour, use other matchers in the Match class.
hasOutput(logicalId, props) 
public hasOutput(logicalId: string, props: any): void
Parameters
- logicalId string— the name of the output.
- props any— the output as should be expected in the template.
Assert that an Output with the given properties exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavour, use other matchers in the Match class.
hasParameter(logicalId, props) 
public hasParameter(logicalId: string, props: any): void
Parameters
- logicalId string— the name of the parameter.
- props any— the parameter as should be expected in the template.
Assert that a Parameter with the given properties exists in the CloudFormation template.
By default, performs partial matching on the parameter, via the Match.objectLike().
To configure different behavior, use other matchers in the Match class.
hasResource(type, props) 
public hasResource(type: string, props: any): void
Parameters
- type string— the resource type;
- props any— the entire defintion of the resource as should be expected in the template.
Assert that a resource of the given type and given definition exists in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike().
To configure different behavour, use other matchers in the Match class.
hasResourceProperties(type, props)  
public hasResourceProperties(type: string, props: any): void
Parameters
- type string— the resource type;
- props any— the 'Properties' section of the resource as should be expected in the template.
Assert that a resource of the given type and properties exists in the CloudFormation template.
By default, performs partial matching on the Properties key of the resource, via the
Match.objectLike(). To configure different behavour, use other matchers in the Match class.
resourceCountIs(type, count)  
public resourceCountIs(type: string, count: number): void
Parameters
- type string— the resource type;
- count number— number of expected instances.
Assert that the given number of resources of the given type exist in the template.
templateMatches(expected) 
public templateMatches(expected: any): void
Parameters
- expected any— the expected CloudFormation template as key-value pairs.
Assert that the CloudFormation template matches the given value.
toJSON() 
public toJSON(): { [string]: any }
Returns
- { [string]: any }
The CloudFormation template deserialized into an object.
static fromJSON(template) 
public static fromJSON(template: { [string]: any }): Template
Parameters
- template { [string]: any }— the CloudFormation template formatted as a nested set of records.
Returns
Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.
static fromStack(stack) 
public static fromStack(stack: Stack): Template
Parameters
- stack Stack— the CDK Stack to run assertions on.
Returns
Base your assertions on the CloudFormation template synthesized by a CDK Stack.
static fromString(template) 
public static fromString(template: string): Template
Parameters
- template string— the CloudFormation template in.
Returns
Base your assertions from an existing CloudFormation template formatted as a JSON string.
