Можно ли добавить несколько тегов в конструкцию AWS CDK? - PullRequest
3 голосов
/ 30 октября 2019

В 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)

Я не смог найти ничего в документации ...

1 Ответ

1 голос
/ 31 октября 2019

Вы правы. В настоящее время в CDK нет способа добавить несколько тегов, используя 1 метод. Но вы можете попытаться найти способ манипулировать aws_cdk.core.TagManager напрямую. Я не рекомендую этого, потому что Python CDK использует JSII для взаимодействия с фактическим CDK, написанным на TypeScript. Вот как выглядит 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])
...