Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
使用 Systems Manager 公共参数引用最新的 AMI
Amazon Systems Manager 为 Amazon 维护的公有 AMI 提供公有参数。您可以在启动实例时使用公有参数来确保使用最新 AMI。例如,公有参数 /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64
在所有区域中均可用,并且始终指向给定区域中适用于 arm64 架构的最新版本 Amazon Linux 2023 AMI。
在以下路径中提供公有参数:
有关更多信息,请参阅《Amazon Systems Manager 用户指南》中的使用公共参数。
列出 Amazon Linux AMI
- Amazon CLI
-
列出当前 Amazon 区域中的 Linux AMI
使用以下 get-parameters-by-path 命令。--path
参数的值因 Linux AMI 而异。
aws ssm get-parameters-by-path \
--path /aws/service/ami-amazon-linux-latest \
--query "Parameters[].Name"
- PowerShell
-
列出当前 Amazon 区域中的 Linux AMI
使用 Get-SSMParametersByPath cmdlet。
Get-SSMParametersByPath `
-Path "/aws/service/ami-amazon-linux-latest" | `
Sort-Object Name | Format-Table Name
列出 Windows AMI
- Amazon CLI
-
列出当前 Amazon 区域中的 Windows AMI
使用以下 get-parameters-by-path 命令。--path
参数的值因 Windows AMI 而异。
aws ssm get-parameters-by-path \
--path /aws/service/ami-windows-latest \
--query "Parameters[].Name"
- PowerShell
-
列出当前 Amazon 区域中的 Windows AMI
使用 Get-SSMParametersByPath cmdlet。
Get-SSMParametersByPath `
-Path "/aws/service/ami-windows-latest" | `
Sort-Object Name | Format-Table Name
使用公有参数启动实例
要在启动实例时指定此公有参数,请使用以下语法 resolve:ssm:public-parameter
,其中 resolve:ssm
是标准前缀,public-parameter
是公有参数的路径和名称。
- Amazon CLI
-
使用公有参数启动实例
使用 run-instances 命令和 --image-id
选项。此示例为该映像 ID 指定了一个 Systems Manager 公有参数,以使用最新版本的 Amazon Linux 2023 AMI 启动实例
--image-id resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64
- PowerShell
-
使用公有参数启动实例
将 New-EC2Instance cmdlet 与 -ImageId
参数结合使用。此示例为该映像 ID 指定了一个 Systems Manager 公有参数,以使用最新版本适用于 Windows Server 2022 的 AMI 启动实例。
-ImageId "resolve:ssm:/aws/service/ami-windows-latest/Windows_Server-2022-English-Full-Base
"
有关使用 Systems Manager 参数的更多示例,请参阅 Query for the latest Amazon Linux AMI IDs Using Amazon Systems Manager Parameter Store 和 Query for the Latest Windows AMI Using Amazon Systems Manager Parameter Store。