调用 AMI 公有参数 - Amazon Systems Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

调用 AMI 公有参数

Amazon Elastic Compute Cloud (Amazon EC2) Amazon Machine Image (AMI) 公有参数在 Amazon Linux、Amazon Linux 2 和 Windows Server 上可通过以下路径获取:

  • Amazon Linux 和 Amazon Linux 2:/aws/service/ami-amazon-linux-latest

  • Windows Server: /aws/service/ami-windows-latest

为 Amazon Linux 和 Amazon Linux 2 调用 AMI 公有参数

您可以在 Amazon Command Line Interface (Amazon CLI) 中使用以下命令查看当前 AMIs中所有 Amazon Linux 和 Amazon Linux 2 Amazon Web Services 区域 的列表。

Linux & macOS
aws ssm get-parameters-by-path \ --path /aws/service/ami-amazon-linux-latest \ --query 'Parameters[].Name'
Windows
aws ssm get-parameters-by-path ^ --path /aws/service/ami-amazon-linux-latest ^ --query Parameters[].Name

此命令会返回如下信息。

[
    "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-ebs",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-minimal-hvm-x86_64-s3",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-minimal-pv-x86_64-s3",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-pv-x86_64-s3",
    "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-arm64-gp2",
    "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs",
    "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2",
    "/aws/service/ami-amazon-linux-latest/amzn2-ami-minimal-hvm-arm64-ebs",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-minimal-hvm-x86_64-ebs",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-minimal-pv-x86_64-ebs",
    "/aws/service/ami-amazon-linux-latest/amzn-ami-pv-x86_64-ebs",
    "/aws/service/ami-amazon-linux-latest/amzn2-ami-minimal-hvm-x86_64-ebs"
]

您可以使用以下命令查看有关这些 AMIs 的详细信息,包括 AMI ID 和 Amazon Resource Name (ARN)。

Linux & macOS
aws ssm get-parameters-by-path \ --path "/aws/service/ami-amazon-linux-latest" \ --region region
Windows
aws ssm get-parameters-by-path ^ --path "/aws/service/ami-amazon-linux-latest" ^ --region region

region 表示 Amazon Systems Manager 支持的 Amazon Web Services 区域 的标识符,例如 us-east-2 对应美国东部(俄亥俄)区域。有关受支持的 region 值的列表,请参阅 Amazon Web Services 一般参考中的 Systems Manager 服务终端节点中的 Region(区域)列。

此命令会返回如下信息。此示例输出已由于空间问题截断。

{
    "Parameters": [
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-ebs",
            "Type": "String",
            "Value": "ami-02f31e7644d23a001",
            "Version": 32,
            "LastModifiedDate": "2021-10-04T14:51:40.313000-07:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-ebs",
            "DataType": "text"
        },
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2",
            "Type": "String",
            "Value": "ami-0a787ac2e0c399e8b",
            "Version": 32,
            "LastModifiedDate": "2021-10-04T14:51:40.424000-07:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2",
            "DataType": "text"
        },
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3",
            "Type": "String",
            "Value": "ami-0437136c909273ff3",
            "Version": 32,
            "LastModifiedDate": "2021-10-04T14:51:40.533000-07:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3",
            "DataType": "text"
        }
    ]
}

您可以使用具有完整 AMI 名称的 GetParameters API 操作查看特定 AMI 的详细信息,包括路径。以下是一个示例命令。

Linux & macOS
aws ssm get-parameters \ --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 \ --region us-east-2
Windows
aws ssm get-parameters ^ --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2 ^ --region us-east-2

该命令将返回以下信息。

{
    "Parameters": [
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2",
            "Type": "String",
            "Value": "ami-074cce78125f09d61",
            "Version": 51,
            "LastModifiedDate": "2021-10-06T16:50:43.294000-07:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2",
            "DataType": "text"
        }
    ],
    "InvalidParameters": []
}

为 Windows Server 调用 AMI 公有参数

您可以在 Amazon CLI 中使用以下命令查看当前 Windows Server中所有 Amazon Web Services 区域 AMIs 的列表。

Linux & macOS
aws ssm get-parameters-by-path \ --path /aws/service/ami-windows-latest \ --query 'Parameters[].Name'
Windows
aws ssm get-parameters-by-path ^ --path /aws/service/ami-windows-latest ^ --query Parameters[].Name

此命令会返回如下信息。此示例输出已由于空间问题截断。

[
    "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Chinese_Simplified-64Bit-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Chinese_Traditional-64Bit-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Dutch-64Bit-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Hungarian-64Bit-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Japanese-64Bit-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers",
    "/aws/service/ami-windows-latest/Windows_Server-2016-German-Full-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-SQL_2017_Web",
    "/aws/service/ami-windows-latest/Windows_Server-2019-English-Core-EKS_Optimized-1.17",
    "/aws/service/ami-windows-latest/amzn2-ami-hvm-2.0.20191217.0-x86_64-gp2-mono",
    "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-English-64Bit-SQL_2016_SP2_Standard",
    "/aws/service/ami-windows-latest/Windows_Server-2012-RTM-Italian-64Bit-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2016-English-Deep-Learning",
    "/aws/service/ami-windows-latest/Windows_Server-2016-English-Full-SQL_2014_SP3_Enterprise",
    "/aws/service/ami-windows-latest/Windows_Server-2019-English-Core-EKS_Optimized-1.21",
    "/aws/service/ami-windows-latest/Windows_Server-2019-Italian-Full-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2019-Japanese-Full-SQL_2017_Enterprise",
    "/aws/service/ami-windows-latest/Windows_Server-2022-Italian-Full-Base",
    "/aws/service/ami-windows-latest/Windows_Server-2022-Portuguese_Brazil-Full-Base",
    "/aws/service/ami-windows-latest/Windows_Server-20H2-English-Core-ContainersLatest",
    "/aws/service/ami-windows-latest/EC2LaunchV2_Preview-Windows_Server-2019-English-Core-Base",
]

您可以使用以下命令查看有关这些 AMIs 的详细信息,包括 AMI ID 和 Amazon Resource Name (ARN)。

Linux & macOS
aws ssm get-parameters-by-path \ --path "/aws/service/ami-windows-latest" \ --region region
Windows
aws ssm get-parameters-by-path ^ --path "/aws/service/ami-windows-latest" ^ --region region

region 表示 Amazon Systems Manager 支持的 Amazon Web Services 区域 的标识符,例如 us-east-2 对应美国东部(俄亥俄)区域。有关受支持的 region 值的列表,请参阅 Amazon Web Services 一般参考中的 Systems Manager 服务终端节点中的 Region(区域)列。

此命令会返回如下信息。此示例输出已由于空间问题截断。

{
    "Parameters": [
        {
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Chinese_Simplified-64Bit-Base",
            "Type": "String",
            "Value": "ami-085a8792434781696",
            "Version": 72,
            "LastModifiedDate": "2021-11-11T16:29:44.401000-08:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Chinese_Simplified-64Bit-Base",
            "DataType": "text"
        },
        {
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Chinese_Traditional-64Bit-Base",
            "Type": "String",
            "Value": "ami-01d65ee0d6d795b37",
            "Version": 72,
            "LastModifiedDate": "2021-11-11T16:30:04.345000-08:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Chinese_Traditional-64Bit-Base",
            "DataType": "text"
        },
        {
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Dutch-64Bit-Base",
            "Type": "String",
            "Value": "ami-0ddf2b503c5585e35",
            "Version": 72,
            "LastModifiedDate": "2021-11-11T16:30:16.207000-08:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-windows-latest/Windows_Server-2012-R2_RTM-Dutch-64Bit-Base",
            "DataType": "text"
        }
    ]
}

您可以使用具有完整 AMI 名称的 GetParameters API 操作查看特定 AMI 的详细信息,包括路径。以下是一个示例命令。

Linux & macOS
aws ssm get-parameters \ --names /aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers \ --region us-east-2
Windows
aws ssm get-parameters ^ --names /aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers ^ --region us-east-2

该命令将返回以下信息。

{
    "Parameters": [
        {
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers",
            "Type": "String",
            "Value": "ami-0581eb234ac9bf3ec",
            "Version": 68,
            "LastModifiedDate": "2021-11-11T16:40:51.934000-08:00",
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers",
            "DataType": "text"
        }
    ],
    "InvalidParameters": []
}