class Template
Language | Type name |
---|---|
.NET | Amazon.CDK.Assertions.Template |
Go | github.com/aws/aws-cdk-go/awscdk/v2/assertions#Template |
Java | software.amazon.awscdk.assertions.Template |
Python | aws_cdk.assertions.Template |
TypeScript (source) | aws-cdk-lib » 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-lib';
import { Template } from 'aws-cdk-lib/assertions';
const stack = new Stack(/* ... */);
// ...
const template = Template.fromStack(stack);
Methods
Name | Description |
---|---|
all | Assert that all resources of the given type contain the given definition in the CloudFormation template. |
all | Assert that all resources of the given type contain the given properties CloudFormation template. |
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. |
resource | Assert that the given number of resources of the given type and properties exists in the CloudFormation 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. |
allResources(type, props)
public allResources(type: string, props: any): void
Parameters
- type
string
— the resource type; - props
any
— the entire definition of the resources as they should be expected in the template.
Assert that all resources of the given type contain the given definition in the CloudFormation template.
By default, performs partial matching on the resource, via the Match.objectLike()
.
To configure different behavior, use other matchers in the Match
class.
allResourcesProperties(type, props)
public allResourcesProperties(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 all resources of the given type contain the given properties CloudFormation template.
By default, performs partial matching on the Properties
key of the resource, via the
Match.objectLike()
. To configure different behavior, use other matchers in the Match
class.
findConditions(logicalId, props?)
public findConditions(logicalId: string, props?: any): { [string]: { [string]: any } }
Parameters
- logicalId
string
— the name of the condition, provide'*'
to match all conditions in the template. - 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, provide'*'
to match all mappings in the template. - 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, provide'*'
to match all outputs in the template. - 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, provide'*'
to match all parameters in the template. - 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, provide'*'
to match all conditions in the template. - 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 behavior, 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, provide'*'
to match all mappings in the template. - 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 behavior, 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, provide'*'
to match all outputs in the template. - 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 behavior, 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, provide'*'
to match all parameters in the template. - 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 definition 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 behavior, 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 behavior, 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.
resourcePropertiesCountIs(type, props, count)
public resourcePropertiesCountIs(type: string, props: any, count: number): void
Parameters
- type
string
— the resource type; - props
any
— the 'Properties' section of the resource as should be expected in the template. - count
number
— number of expected instances.
Assert that the given number of resources of the given type and properties exists in the CloudFormation 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, templateParsingOptions?)
public static fromJSON(template: { [string]: any }, templateParsingOptions?: TemplateParsingOptions): Template
Parameters
- template
{ [string]: any }
— the CloudFormation template formatted as a nested set of records. - templateParsingOptions
Template
— Optional param to configure template parsing behavior, such as disregarding circular dependencies.Parsing Options
Returns
Base your assertions from an existing CloudFormation template formatted as an in-memory JSON object.
static fromStack(stack, templateParsingOptions?)
public static fromStack(stack: Stack, templateParsingOptions?: TemplateParsingOptions): Template
Parameters
- stack
Stack
— the CDK Stack to run assertions on. - templateParsingOptions
Template
— Optional param to configure template parsing behavior, such as disregarding circular dependencies.Parsing Options
Returns
Base your assertions on the CloudFormation template synthesized by a CDK Stack
.
static fromString(template, templateParsingOptions?)
public static fromString(template: string, templateParsingOptions?: TemplateParsingOptions): Template
Parameters
- template
string
— the CloudFormation template in. - templateParsingOptions
Template
— Optional param to configure template parsing behavior, such as disregarding circular dependencies.Parsing Options
Returns
Base your assertions from an existing CloudFormation template formatted as a JSON string.