gpt4 book ai didi

python - 是否可以在 AWS CDK 构造上添加多个标签?

转载 作者:行者123 更新时间:2023-11-28 17:55:38 24 4
gpt4 key购买 nike

在 python 中,我正在做这样的事情来为构造的所有资源添加标签:core.Tag.add(construct, 'Key', 'Value')

我的问题是,CDK 是否支持在一个命令中添加多个标签,或者我是否必须迭代以一次添加一对。像这样:

tags = {'Key1': 'Value1', 'Key2': 'Value2'}
for key, value in tags.items():
core.Tag.add(construct, key, value)

我在文档中找不到任何内容...

最佳答案

你是对的。目前 CDK 中无法使用 1 方法添加多个标签。但是您可以尝试找出一种直接操作 aws_cdk.core.TagManager 的方法。我不推荐这样做,因为 Python CDK 使用 JSII 与用 TypeScript 编写的实际 CDK 交互。这是 core.Tag.add 的样子

    @jsii.member(jsii_name="add")
@classmethod
def add(cls, scope: "Construct", key: str, value: str, *, apply_to_launched_instances: typing.Optional[bool]=None, exclude_resource_types: typing.Optional[typing.List[str]]=None, include_resource_types: typing.Optional[typing.List[str]]=None, priority: typing.Optional[jsii.Number]=None) -> None:
"""add tags to the node of a construct and all its the taggable children.

:param scope: -
:param key: -
:param value: -
:param props: -
:param apply_to_launched_instances: Whether the tag should be applied to instances in an AutoScalingGroup. Default: true
:param exclude_resource_types: An array of Resource Types that will not receive this tag. An empty array will allow this tag to be applied to all resources. A non-empty array will apply this tag only if the Resource type is not in this array. Default: []
:param include_resource_types: An array of Resource Types that will receive this tag. An empty array will match any Resource. A non-empty array will apply this tag only to Resource types that are included in this array. Default: []
:param priority: Priority of the tag operation. Higher or equal priority tags will take precedence. Setting priority will enable the user to control tags when they need to not follow the default precedence pattern of last applied and closest to the construct in the tree. Default: Default priorities: - 100 for {@link SetTag} - 200 for {@link RemoveTag} - 50 for tags added directly to CloudFormation resources
"""
props = TagProps(apply_to_launched_instances=apply_to_launched_instances, exclude_resource_types=exclude_resource_types, include_resource_types=include_resource_types, priority=priority)

return jsii.sinvoke(cls, "add", [scope, key, value, props])

关于python - 是否可以在 AWS CDK 构造上添加多个标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58632480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com