【问题标题】:is there any way to find last 3 aws launch template version using python?有没有办法使用 python 找到最后 3 个 aws 启动模板版本?
【发布时间】:2022-07-08 07:58:08
【问题描述】:

#!/usr/bin/python

导入boto3

导入系统

ec2 = boto3.client('ec2', region_name=region)

template_versions = ec2.describe_launch_template_versions( 版本=[“$最新”], )

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python-3.x


【解决方案1】:

要回答这个问题,我想说为什么要得到这个并不容易。 你需要做 template_versions = ec2.describe_launch_template_versions( LaunchTemplateId="...", ) (您也可以使用 LaunchTemplateName)

然后取回所有版本

理论上,您可以像上面一样取回最新版本,然后获取该版本号。然后减去 3 并设置最小版本和最大版本。问题是您可以删除版本。所以你可以说一个最小值和最大值,但只能得到 1、2 或 3 个结果。我会说如果你想要 3 个结果找到最新的版本号 -10,如果小于 1 则将 min 设置为 1。然后根据 VersionNumber 对数组进行排序。

所以像 最新版本 = 18 template_versions = ec2.describe_launch_template_versions( LaunchTemplateId="...", MinVersion="8",MaxVersion="18" ).get("LaunchTemplateVersions")

template_versions.sort(key=lambda x: x["VersionNumber"], reverse=True)

https://www.techiedelight.com/sort-list-of-objects-python/

理论上,前3个应该是最新的3个版本。但同样有可能得到一个小于 3 的数字

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_launch_template_versions

【讨论】:

    猜你喜欢
    • 2011-10-11
    • 2013-06-18
    • 1970-01-01
    • 2022-09-27
    • 2022-09-24
    • 1970-01-01
    • 2020-08-11
    • 2013-07-11
    • 2018-12-09
    相关资源
    最近更新 更多