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

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

调用 AMI 公有参数

Amazon EC2 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 Linux 中使用以下命令查看当前 Amazon Linux 2 区域中所有 AWS 和 AWS CLI AMI 的列表。

Linux
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"
]

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

Linux
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 表示 AWS Systems Manager 支持的 AWS 区域的标识符,如美国东部(俄亥俄)区域的 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-0d75cc1d706735521",
            "Version": 7,
            "LastModifiedDate": 1543873943.358,
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-ebs"
        },
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2",
            "Type": "String",
            "Value": "ami-0cd3dfa4e37921605",
            "Version": 7,
            "LastModifiedDate": 1543873943.47,
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-gp2"
        },
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3",
            "Type": "String",
            "Value": "ami-0a0e3ff8af8d19497",
            "Version": 7,
            "LastModifiedDate": 1543873943.576,
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-s3"
        },
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn-ami-minimal-hvm-x86_64-ebs",
            "Type": "String",
            "Value": "ami-0786a9626196d6dac",
            "Version": 7,
            "LastModifiedDate": 1543873943.682,
            "ARN": "arn:aws:ssm:us-east-2::parameter/aws/service/ami-amazon-linux-latest/amzn-ami-minimal-hvm-x86_64-ebs"
        },

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

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

该命令将返回以下信息。

{
    "Parameters": [
        {
            "Name": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2",
            "Type": "String",
            "Value": "ami-061392db613a6357b",
            "Version": 16,
            "LastModifiedDate": 1552519670.776,
            "ARN": "arn:aws:ssm:us-west-2::parameter/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
        }
    ],
    "InvalidParameters": []
}

调用 Windows Server 的 AMI 公有参数

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

Linux
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/amzn2-ami-hvm-2.0.20190313-x86_64-gp2-SQL_2017_Express",
    "/aws/service/ami-windows-latest/amzn2-ami-hvm-2.0.20191217.0-x86_64-gp2-mono",
    "/aws/service/ami-windows-latest/EC2LaunchV2_Preview-Windows_Server-2019-English-Core-Base",
    "/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-2016-Korean-Full-SQL_2016_SP2_Standard",
    "/aws/service/ami-windows-latest/Windows_Server-2019-English-Core-EKS_Optimized-1.17",
]

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

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

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

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

{
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers",
            "Type": "String",
            "Value": "ami-0b19f0a8c08620b34",
            "Version": 53,
            "LastModifiedDate": "2020-09-10T19:49:05.760000-07:00",
            "ARN": "arn:aws:ssm:us-east-1::parameter/aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers",
            "DataType": "text"
        },
        {
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2016-German-Full-Base",
            "Type": "String",
            "Value": "ami-068badb2c4fe9d831",
            "Version": 53,
            "LastModifiedDate": "2020-09-10T19:53:44.049000-07:00",
            "ARN": "arn:aws:ssm:us-east-1::parameter/aws/service/ami-windows-latest/Windows_Server-2016-German-Full-Base",
            "DataType": "text"
        },
        {
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-SQL_2017_Web",
            "Type": "String",
            "Value": "ami-0b12e609d6733dac7",
            "Version": 20,
            "LastModifiedDate": "2020-09-10T19:55:24.166000-07:00",
            "ARN": "arn:aws:ssm:us-east-1::parameter/aws/service/ami-windows-latest/Windows_Server-2016-Japanese-Full-SQL_2017_Web",
            "DataType": "text"
        },

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

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

该命令将返回以下信息。

{
    "Parameters": [
        {
            "Name": "/aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers",
            "Type": "String",
            "Value": "ami-0315ac376f3dac169",
            "Version": 53,
            "LastModifiedDate": "2020-09-10T19:50:01.955000-07:00",
            "ARN": "arn:aws:ssm:us-west-2::parameter/aws/service/ami-windows-latest/Windows_Server-2016-English-Core-Containers",
            "DataType": "text"
        }
    ],
    "InvalidParameters": []
}