管理允許的 AMI 的設定 - Amazon Elastic Compute Cloud

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

管理允許的 AMI 的設定

您可管理允許的 AMI 的設定。這些設定依據每個帳戶每個區域設定。

啟用允許 AMI

您可啟用允許的 AMI 並指定允許的 AMI 條件 建議以稽核模式開始,該模式可顯示哪些 AMI 會受條件影響,而不會實際限制存取權。

Console
若要啟用允許 AMI
  1. 前往 https://console.aws.amazon.com/ec2/ 開啟 Amazon EC2 主控台。

  2. 在導覽窗格中,選擇 Dashboard (儀表板)

  3. 帳戶屬性 (右上角),選擇允許 AMI

  4. 允許的 AMI 索引標籤上,選擇管理

  5. 針對允許的 AMI 設定,選擇稽核模式已啟用。建議以稽核模式開始,測試條件,然後返回此步驟,以便啟用允許的 AMI。

  6. (選用) 針對 AMI 條件,輸入 JSON 格式的條件。

  7. 選擇更新

AWS CLI
若要啟用允許 AMI

請使用 enable-allowed-images-settings 命令。

aws ec2 enable-allowed-images-settings --allowed-images-settings-state enabled

如需轉為啟用稽核模式,指定 audit-mode 而不是 enabled

aws ec2 enable-allowed-images-settings --allowed-images-settings-state audit-mode
PowerShell
若要啟用允許 AMI

使用 Enable-EC2AllowedImagesSetting cmdlet。

Enable-EC2AllowedImagesSetting -AllowedImagesSettingsState enabled

如需轉為啟用稽核模式,指定 audit-mode 而不是 enabled

Enable-EC2AllowedImagesSetting -AllowedImagesSettingsState audit-mode

設定允許的 AMI 條件

在啟用允許的 AMI 之後,您可設定或取代允許的 AMI 條件。

如需了解正確的組態與有效值,請參閱 允許的 AMI 組態允許的 AMI 參數

Console
如需設定允許的 AMI 條件
  1. 前往 https://console.aws.amazon.com/ec2/ 開啟 Amazon EC2 主控台。

  2. 在導覽窗格中,選擇 Dashboard (儀表板)

  3. 帳戶屬性 (右上角),選擇允許 AMI

  4. 允許的 AMI 索引標籤上,選擇管理

  5. 針對 AMI 條件,輸入 JSON 格式的條件。

  6. 選擇更新

AWS CLI
如需設定允許的 AMI 條件

請使用 replace-image-criteria-in-allowed-images-settings 命令,然後指定包含允許的 AMI 條件的 JSON 檔案。

aws ec2 replace-image-criteria-in-allowed-images-settings --cli-input-json file://file_name.json
PowerShell
如需設定允許的 AMI 條件

請使用 Set-EC2ImageCriteriaInAllowedImagesSetting cmdlet,然後指定包含允許的 AMI 條件的 JSON 檔案。

$imageCriteria = Get-Content -Path .\file_name.json | ConvertFrom-Json Set-EC2ImageCriteriaInAllowedImagesSetting -ImageCriterion $imageCriteria

停用允許 AMI

您可如下所示停用允許的 AMI。

Console
若要停用允許 AMI
  1. 前往 https://console.aws.amazon.com/ec2/ 開啟 Amazon EC2 主控台。

  2. 在導覽窗格中,選擇 Dashboard (儀表板)

  3. 帳戶屬性 (右上角),選擇允許 AMI

  4. 允許的 AMI 索引標籤上,選擇管理

  5. 對於允許 AMI 設定,選擇已停用

  6. 選擇更新

AWS CLI
若要停用允許 AMI

請使用 disable-allowed-images-settings 命令。

aws ec2 disable-allowed-images-settings
PowerShell
若要停用允許 AMI

使用 Disable-EC2AllowedImagesSetting cmdlet。

Disable-EC2AllowedImagesSetting

獲取允許的 AMI 條件

您可獲取允許的 AMI 設定的目前狀態及允許的 AMI 條件。

Console
如需獲取允許的 AMI 狀態及條件
  1. 前往 https://console.aws.amazon.com/ec2/ 開啟 Amazon EC2 主控台。

  2. 在導覽窗格中,選擇 Dashboard (儀表板)

  3. 帳戶屬性 (右上角),選擇允許 AMI

  4. 允許的 AMI 索引標籤上,將允許的 AMI 設定設定為已啟用已停用稽核模式

  5. 若允許的 AMI 狀態為已啟用稽核模式AMI 條件,會顯示 JSON 格式的 AMI 條件。

AWS CLI
如需獲取允許的 AMI 狀態及條件

請使用 get-allowed-images-settings 命令。

aws ec2 get-allowed-images-settings

在下面的範例輸出中,狀態為 audit-mode,且映像條件已在帳戶中設定。

{ "State": "audit-mode", "ImageCriteria": [ { "MarketplaceProductCodes": [ "abcdefg1234567890" ] }, { "ImageProviders": [ "123456789012", "123456789013" ], "CreationDateCondition": { "MaximumDaysSinceCreated": 300 } }, { "ImageProviders": [ "123456789014" ], "ImageNames": [ "golden-ami-*" ] }, { "ImageProviders": [ "amazon" ], "DeprecationTimeCondition": { "MaximumDaysSinceDeprecated": 0 } } ], "ManagedBy": "account" }
PowerShell
如需獲取允許的 AMI 狀態及條件

使用 Get-EC2AllowedImagesSetting cmdlet。

Get-EC2AllowedImagesSetting | Select-Object ` State, ` ManagedBy, ` @{Name='ImageProviders'; Expression={($_.ImageCriteria.ImageProviders)}}, ` @{Name='MarketplaceProductCodes'; Expression={($_.ImageCriteria.MarketplaceProductCodes)}}, ` @{Name='ImageNames'; Expression={($_.ImageCriteria.ImageNames)}}, ` @{Name='MaximumDaysSinceCreated'; Expression={($_.ImageCriteria.CreationDateCondition.MaximumDaysSinceCreated)}}, ` @{Name='MaximumDaysSinceDeprecated'; Expression={($_.ImageCriteria.DeprecationTimeCondition.MaximumDaysSinceDeprecated)}}

在下面的範例輸出中,狀態為 audit-mode,且映像條件已在帳戶中設定。

State : audit-mode ManagedBy : account ImageProviders : {123456789012, 123456789013, 123456789014, amazon} MarketplaceProductCodes : {abcdefg1234567890} ImageNames : {golden-ami-*} MaximumDaysSinceCreated : 300 MaximumDaysSinceDeprecated: 0

尋找允許的 AMI

您可尋找依據目前允許的 AMI 條件而被允許或不被允許的 AMI。

注意

允許的 AMI 必須為稽核模式。

Console
如需檢查 AMI 是否滿足允許的 AMI 條件
  1. 前往 https://console.aws.amazon.com/ec2/ 開啟 Amazon EC2 主控台。

  2. 在導覽窗格中,選擇 AMI

  3. 請選取 AMI。

  4. 詳細資料索引標籤 (如選取核取方塊) 或在摘要區域 (如選取 AMI ID),找到允許映像欄位。

    • – AMI 滿足允許的 AMI 條件。在啟用允許的 AMI 之後,您帳戶中的使用者將可使用此 AMI。

    • – AMI 不滿足允許的 AMI 條件。

  5. 在導覽窗格中,選擇 AMI Catalog (AMI 型錄)。

    當 AMI 標記為不允許時,表示其不符合允許 AMI 條件。當啟用允許 AMI 時,您帳戶的使用者將無法看到或使用此 AMI。

AWS CLI
如需檢查 AMI 是否滿足允許的 AMI 條件

使用 describe-images 命令。

aws ec2 describe-images \ --image-id ami-0abcdef1234567890 \ --query Images[].ImageAllowed \ --output text

以下為範例輸出。

True
如需尋找滿足允許的 AMI 條件的 AMI

使用 describe-images 命令。

aws ec2 describe-images \ --filters "Name=image-allowed,Values=true" \ --max-items 10 \ --query Images[].ImageId

以下為範例輸出。

ami-000eaaa8be2fd162a ami-000f82db25e50de8e ami-000fc21eb34c7a9a6 ami-0010b876f1287d7be ami-0010b929226fe8eba ami-0010957836340aead ami-00112c992a47ba871 ami-00111759e194abcc1 ami-001112565ffcafa5e ami-0011e45aaee9fba88
PowerShell
如需檢查 AMI 是否滿足允許的 AMI 條件

使用 Get-EC2Image cmdlet。

(Get-EC2Image -ImageId ami-0abcdef1234567890).ImageAllowed

以下為範例輸出。

True
如需尋找滿足允許的 AMI 條件的 AMI

使用 Get-EC2Image cmdlet。

Get-EC2Image ` -Filter @{Name="image-allows";Values="true"} ` -MaxResult 10 | ` Select ImageId

以下為範例輸出。

ami-000eaaa8be2fd162a ami-000f82db25e50de8e ami-000fc21eb34c7a9a6 ami-0010b876f1287d7be ami-0010b929226fe8eba ami-0010957836340aead ami-00112c992a47ba871 ami-00111759e194abcc1 ami-001112565ffcafa5e ami-0011e45aaee9fba88

尋找透過不允許的 AMI 啟動的執行個體

您可確定使用不滿足允許的 AMI 條件的 AMI 啟動的執行個體。

Console
如需檢查識別執行個體是否使用不允許的 AMI 啟動
  1. 前往 https://console.aws.amazon.com/ec2/ 開啟 Amazon EC2 主控台。

  2. 在導覽窗格中,選擇執行個體

  3. 選取執行個體。

  4. 詳細資訊索引標籤的執行個體詳細資訊下,找到允許的映像

    • – AMI 滿足允許的 AMI 條件。

    • – AMI 不滿足允許的 AMI 條件。

AWS CLI
如需尋找使用不允許的 AMI 啟動的執行個體

請使用 image-allowed 篩選條件並搭配 describe-instance-image-metadata 命令。

aws ec2 describe-instance-image-metadata \ --filters "Name=image-allowed,Values=false" \ --query "InstanceImageMetadata[*].[InstanceId,ImageMetadata.ImageId]" \ --output table

以下為範例輸出。

-------------------------------------------------- | DescribeInstanceImageMetadata | +----------------------+-------------------------+ | i-08fd74f3f1595fdbd | ami-09245d5773578a1d6 | | i-0b1bf24fd4f297ab9 | ami-07cccf2bd80ed467f | | i-026a2eb590b4f7234 | ami-0c0ec0a3a3a4c34c0 | | i-006a6a4e8870c828f | ami-0a70b9d193ae8a799 | | i-0781e91cfeca3179d | ami-00c257e12d6828491 | | i-02b631e2a6ae7c2d9 | ami-0bfddf4206f1fa7b9 | +----------------------+-------------------------+
PowerShell
如需尋找使用不允許的 AMI 啟動的執行個體

使用 Get-EC2InstanceImageMetadata cmdlet。

Get-EC2InstanceImageMetadata ` -Filter @{Name="image-allowed";Values="false"} | ` Select InstanceId, @{Name='ImageId'; Expression={($_.ImageMetadata.ImageId)}}

以下為範例輸出。

InstanceId ImageId ---------- ------- i-08fd74f3f1595fdbd ami-09245d5773578a1d6 i-0b1bf24fd4f297ab9 ami-07cccf2bd80ed467f i-026a2eb590b4f7234 ami-0c0ec0a3a3a4c34c0 i-006a6a4e8870c828f ami-0a70b9d193ae8a799 i-0781e91cfeca3179d ami-00c257e12d6828491 i-02b631e2a6ae7c2d9 ami-0bfddf4206f1fa7b9
AWS Config

您可以新增 ec2-instance-launched-with-allowed-ami AWS Config 規則、根據您的需求進行設定,然後使用它來評估您的執行個體。

如需詳細資訊,請參閱《 AWS Config 開發人員指南》中的新增 AWS Config 規則ec2-instance-launched-with-allowed-ami