

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

# 使用 AWS Systems Manager 參數存放區 API 擷取 macOS AMI IDs
<a name="macos-ami-ids-parameter-store"></a>

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

**所需的許可**  
若要執行此動作，[IAM 主體](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts)必須具有呼叫 `ssm:GetParameter` API 動作的權限。

**AWS 區域 使用 檢視目前 中所有 macOS AMIs的清單 AWS CLI**  
使用下列 [get-parameters-by-path](https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameters-by-path.html) 命令來檢視目前區域中所有 macOS AMI 的清單。

```
aws ssm get-parameters-by-path --path /aws/service/ec2-macos --recursive --query "Parameters[].Name"
```

**使用 擷取最新主要 macOS AMI 的 AMI ID AWS CLI**  
將下列 [get-parameter](https://docs.aws.amazon.com/cli/latest/reference/ssm/get-parameter.html) 命令搭配子參數 `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 公有參數](https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-public-parameters-ami.html#public-parameters-ami-macos)。