使用 Windows PowerShell 來尋找 Amazon Machine Image - AWS Tools for PowerShell

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 Windows PowerShell 來尋找 Amazon Machine Image

啟動 Amazon EC2 執行個體時,您會指定 Amazon Machine Image (AMI) 做為執行個體的範本。然而,AWS Windows AMI 的 ID 經常會變更,因為 AWS 會提供新的 AMI 最新的更新並強化安全。您可使用 Get-EC2ImageGet-EC2ImageByName Cmdlet 來尋找目前的 Windows AMI 並取得其 ID。

Get-EC2Image

Get-EC2Image cmdlet 會擷取您可使用的 AMI 清單。

搭配陣列值 -Owner 使用 amazon, self 參數,讓 Get-EC2Image 僅擷取屬於 Amazon 或您的 AMI。在此內容中,「您」指的是您使用其憑證來呼叫 Cmdlet 的使用者。

PS > Get-EC2Image -Owner amazon, self

您可使用 -Filter 參數來限定結果範圍。欲指定篩選條件,請建立類型 Amazon.EC2.Model.Filter 的物件。例如,下列篩選條件只會顯示 Windows AMI。

$platform_values = New-Object 'collections.generic.list[string]' $platform_values.add("windows") $filter_platform = New-Object Amazon.EC2.Model.Filter -Property @{Name = "platform"; Values = $platform_values} Get-EC2Image -Owner amazon, self -Filter $filter_platform

下列範例為 cmdlet 回傳的 AMI 之一;上述命令的輸出實際提供許多 AMI 的資訊。

Architecture : x86_64 BlockDeviceMappings : {/dev/sda1, xvdca, xvdcb, xvdcc…} CreationDate : 2019-06-12T10:41:31.000Z Description : Microsoft Windows Server 2019 Full Locale English with SQL Web 2017 AMI provided by Amazon EnaSupport : True Hypervisor : xen ImageId : ami-000226b77608d973b ImageLocation : amazon/Windows_Server-2019-English-Full-SQL_2017_Web-2019.06.12 ImageOwnerAlias : amazon ImageType : machine KernelId : Name : Windows_Server-2019-English-Full-SQL_2017_Web-2019.06.12 OwnerId : 801119661308 Platform : Windows ProductCodes : {} Public : True RamdiskId : RootDeviceName : /dev/sda1 RootDeviceType : ebs SriovNetSupport : simple State : available StateReason : Tags : {} VirtualizationType : hvm

Get-EC2ImageByName

Get-EC2ImageByName Cmdlet 可讓您依據您感興趣的伺服器組態類型,篩選 AWS Windows AMI 的清單。

不帶參數執行時,Cmdlet 會發出目前篩選條件的整組名稱,如下所示:

PS > Get-EC2ImageByName WINDOWS_2016_BASE WINDOWS_2016_NANO WINDOWS_2016_CORE WINDOWS_2016_CONTAINER WINDOWS_2016_SQL_SERVER_ENTERPRISE_2016 WINDOWS_2016_SQL_SERVER_STANDARD_2016 WINDOWS_2016_SQL_SERVER_WEB_2016 WINDOWS_2016_SQL_SERVER_EXPRESS_2016 WINDOWS_2012R2_BASE WINDOWS_2012R2_CORE WINDOWS_2012R2_SQL_SERVER_EXPRESS_2016 WINDOWS_2012R2_SQL_SERVER_STANDARD_2016 WINDOWS_2012R2_SQL_SERVER_WEB_2016 WINDOWS_2012R2_SQL_SERVER_EXPRESS_2014 WINDOWS_2012R2_SQL_SERVER_STANDARD_2014 WINDOWS_2012R2_SQL_SERVER_WEB_2014 WINDOWS_2012_BASE WINDOWS_2012_SQL_SERVER_EXPRESS_2014 WINDOWS_2012_SQL_SERVER_STANDARD_2014 WINDOWS_2012_SQL_SERVER_WEB_2014 WINDOWS_2012_SQL_SERVER_EXPRESS_2012 WINDOWS_2012_SQL_SERVER_STANDARD_2012 WINDOWS_2012_SQL_SERVER_WEB_2012 WINDOWS_2012_SQL_SERVER_EXPRESS_2008 WINDOWS_2012_SQL_SERVER_STANDARD_2008 WINDOWS_2012_SQL_SERVER_WEB_2008 WINDOWS_2008R2_BASE WINDOWS_2008R2_SQL_SERVER_EXPRESS_2012 WINDOWS_2008R2_SQL_SERVER_STANDARD_2012 WINDOWS_2008R2_SQL_SERVER_WEB_2012 WINDOWS_2008R2_SQL_SERVER_EXPRESS_2008 WINDOWS_2008R2_SQL_SERVER_STANDARD_2008 WINDOWS_2008R2_SQL_SERVER_WEB_2008 WINDOWS_2008RTM_BASE WINDOWS_2008RTM_SQL_SERVER_EXPRESS_2008 WINDOWS_2008RTM_SQL_SERVER_STANDARD_2008 WINDOWS_2008_BEANSTALK_IIS75 WINDOWS_2012_BEANSTALK_IIS8 VPC_NAT

欲限縮回傳的映像組,請使用 Names 參數來指定一個或多個篩選條件名稱。

PS > Get-EC2ImageByName -Names WINDOWS_2016_CORE Architecture : x86_64 BlockDeviceMappings : {/dev/sda1, xvdca, xvdcb, xvdcc…} CreationDate : 2019-08-16T09:36:09.000Z Description : Microsoft Windows Server 2016 Core Locale English AMI provided by Amazon EnaSupport : True Hypervisor : xen ImageId : ami-06f2a2afca06f15fc ImageLocation : amazon/Windows_Server-2016-English-Core-Base-2019.08.16 ImageOwnerAlias : amazon ImageType : machine KernelId : Name : Windows_Server-2016-English-Core-Base-2019.08.16 OwnerId : 801119661308 Platform : Windows ProductCodes : {} Public : True RamdiskId : RootDeviceName : /dev/sda1 RootDeviceType : ebs SriovNetSupport : simple State : available StateReason : Tags : {} VirtualizationType : hvm