【问题标题】:Get the latest Windows 2012R2 base AMI id using aws cli?使用 aws cli 获取最新的 Windows 2012R2 基础 AMI id?
【发布时间】:2017-08-21 13:15:47
【问题描述】:

有没有办法使用 aws cli 获取最新的 Windows 2012R2 基础 AMI id?

类似Get-EC2ImageByName -Names WINDOWS_2012R2_BASE 在 Powershell 中的东西。我想在 Linux 中使用它。

我已尝试使用 aws ec2 describe-images --owners amazon --filters "Name=name,Values=Windows_Server-2012-R2_RTM-English-64Bit-Base-*" 但感觉就像一个黑客。有没有更好的方法来做到这一点,比如在 Powershell 中?

【问题讨论】:

标签: amazon-web-services aws-cli amazon-ami aws-powershell


【解决方案1】:

您描述的“hack”是在 AWS CLI 中检索这些的正确方法。事实上,这就是 PowerShell 工具的Get-EC2ImageByName 在幕后所做的;它将原始 AMI 名称(由ShowFilter 参数公开)映射到由AllAvailable 参数公开的预定义名称模式。

您可以通过列出ShowFilter 参数来看到这一点;第一个结果与您列出的名称值匹配:

C:/ > get-ec2imagebyname -ShowFilters

Windows_Server-2012-R2_RTM-English-64Bit-Base*
Windows_Server-2012-R2_RTM-English-64Bit-SQL_2014_SP1_Express*
Windows_Server-2012-R2_RTM-English-64Bit-SQL_2014_SP1_Standard*
Windows_Server-2012-R2_RTM-English-64Bit-SQL_2014_SP1_Web*
Windows_Server-2012-RTM-English-64Bit-Base*
...

要仅从 AWS CLI 获取最新的 Windows 2012 R2 AMI ID,请按 CreationDate 对查询进行排序并限制为仅最后一个结果。

示例:

aws ec2 describe-images \
    --owners 'amazon' \
    --filters 'Name=name,Values=Windows_Server-2012-R2_RTM-English-64Bit-Base*' \
    --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \
    --output 'text'

输出:

ami-11e84107

进一步阅读

【讨论】:

    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2020-10-29
    相关资源
    最近更新 更多