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. |
Conditions(logicalId, props?)
findpublic 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.
Mappings(logicalId, props?)
findpublic 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.
Outputs(logicalId, props?)
findpublic 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.
Parameters(logicalId, props?)
findpublic 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.
Resources(type, props?)
findpublic 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.
Condition(logicalId, props)
haspublic 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.
Mapping(logicalId, props)
haspublic 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.
Output(logicalId, props)
haspublic 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.
Parameter(logicalId, props)
haspublic 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.
Resource(type, props)
haspublic 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.
ResourceProperties(type, props)
haspublic 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.
CountIs(type, count)
resourcepublic 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.
Matches(expected)
templatepublic templateMatches(expected: any): void
Parameters
- expected
any
— the expected CloudFormation template as key-value pairs.
Assert that the CloudFormation template matches the given value.
JSON()
topublic toJSON(): { [string]: any }
Returns
{ [string]: any }
The CloudFormation template deserialized into an object.
JSON(template)
static frompublic 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.
Stack(stack)
static frompublic 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
.
String(template)
static frompublic 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.