Tags

class aws_cdk.assertions.Tags(*args: Any, **kwargs)

Bases: object

Allows assertions on the tags associated with a synthesized CDK stack’s manifest.

Stack tags are not part of the synthesized template, so can only be checked from the manifest in this manner.

ExampleMetadata:

infused

Example:

tags = Tags.from_stack(stack)

# using a default 'objectLike' Matcher
tags.has_values({
    "tag-name": "tag-value"
})

# ... with Matchers embedded
tags.has_values({
    "tag-name": Match.string_like_regexp("value")
})

# or another object Matcher at the top level
tags.has_values(Match.object_equals({
    "tag-name": Match.any_value()
}))

Methods

all()

Get the tags associated with the manifest.

This will be an empty object if no tags were supplied.

Return type:

Mapping[str, str]

Returns:

The tags associated with the stack’s synthesized manifest.

has_none()

Assert that the there are no tags associated with the synthesized CDK Stack’s manifest.

This is a convenience method over hasValues(Match.exact({})), and is present because the more obvious method of detecting no tags (Match.absent()) will not work. Manifests default the tag set to an empty object.

Return type:

None

has_values(tags)

Assert that the given Matcher or object matches the tags associated with the synthesized CDK Stack’s manifest.

Parameters:

tags (Any) – the expected set of tags. This should be a string or Matcher object.

Return type:

None

Static Methods

classmethod from_stack(stack)

Find tags associated with a synthesized CDK Stack.

Parameters:

stack (Stack) – the CDK Stack to find tags on.

Return type:

Tags