使用 AWS Systems Manager 參數存放區 API 擷取 macOS AMI IDs - Amazon Elastic Compute Cloud

使用 AWS Systems Manager 參數存放區 API 擷取 macOS AMI IDs

在您啟動執行個體時,必須指定 AMI。AWS 區域 專用的 AMI、作業系統和處理器架構。您可以在 AWS 區域 中檢視所有的 macOS AMI,並透過查詢 AWS Systems Manager 參數存放區 API 來擷取最新的 macOS AMI。使用這些公有參數時,您不需要手動查詢 macOS AMI ID。公有參數同時適用於 x86 和 ARM64 macOS AMI,還能與您現有的 AWS CloudFormation 範本整合。

所需的許可

若要執行此動作,IAM 主體必須具有呼叫 ssm:GetParameter API 動作的權限。

使用 AWS CLI 檢視目前 AWS 區域 中所有 macOS AMI 的清單

使用下列 get-parameters-by-path 命令來檢視目前區域中所有 macOS AMI 的清單。

aws ssm get-parameters-by-path --path /aws/service/ec2-macos --recursive --query "Parameters[].Name"
使用 AWS CLI 擷取最新主要 macOS AMI 的 AMI ID

將下列 get-parameter 命令搭配子參數 image_id 使用。在下列範例中,將 sonoma 取代為 macOS 支援的主要版本、將 x86_64_mac 取代為處理器,並將 region-code 取代為您希望取得最新 macOS AMI ID 的支援 AWS 區域。

aws ssm get-parameter --name /aws/service/ec2-macos/sonoma/x86_64_mac/latest/image_id --region region-code

如需詳細資訊,請參閱「AWS Systems Manager 使用者指南」中的呼叫 macOS 的 AMI 公有參數