AWS Systems Manager
用户指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

使用公有参数

有些 AWS 服务作为 Systems Manager 公有 参数发布有关常见构件的信息。例如,Amazon Elastic Compute Cloud (Amazon EC2) 服务作为公有参数发布有关 Amazon 系统映像 (AMI) 的信息。您可以使用 GetParametersByPathGetParameterGetParameters API 操作从您的脚本和代码调用此信。

本主题介绍了如何使用 AWS CLI 调用公有参数。

调用 AMI 公有参数

Amazon EC2 AMI 公有参数从以下路径提供:

  • /aws/service/ami-amazon-linux-latest

  • /aws/service/ami-windows-latest

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

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)。

aws ssm get-parameters-by-path --path "/aws/service/ami-amazon-linux-latest" --region 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 的详细信息,包括路径。以下是一个示例命令。

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": []
}

调用 ECS 优化 AMI 公有参数

Amazon Elastic Container Service (Amazon ECS) 服务作为公有参数发布最新的 Amazon ECS 优化 AMI 的名称。我们鼓励用户在为 Amazon ECS 创建新 Amazon EC2 集群时使用此 AMI,因为优化的 AMI 包括错误修复和功能更新。使用以下命令查看最新的 Amazon ECS 优化 AMI 的名称。

aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux/recommended

此命令会返回如下信息。

{
    "Parameters": [
        {
            "Name": "/aws/service/ecs/optimized-ami/amazon-linux/recommended",
            "Type": "String",
            "Value": "{\"schema_version\":1,\"image_name\":\"amzn-ami-2018.03.p-amazon-ecs-optimized\",\"image_id\":\"ami-01a82c3fce2c3ba58\",\"os\":\"Amazon Linux\",\"ecs_runtime_version\":\"Docker version 18.06.1-ce\",\"ecs_agent_version\":\"1.27.0\"}",
            "Version": 22,
            "LastModifiedDate": 1555434745.425,
            "ARN": "arn:aws:ssm:us-west-2::parameter/aws/service/ecs/optimized-ami/amazon-linux/recommended"
        }
    ],
    "InvalidParameters": []
}

调用 AWS 服务、区域和终端节点公有参数

您可以使用以下路径调用 AWS 服务、区域和终端节点公有参数。

/aws/service/global-infrastructure

您可以在 AWS CLI 中使用以下命令查看所有活动 AWS 区域的列表。

aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/regions --query Parameters[].Name

此命令会返回如下信息。

"/aws/service/global-infrastructure/regions/ap-northeast-1"
"/aws/service/global-infrastructure/regions/eu-central-1"
"/aws/service/global-infrastructure/regions/eu-north-1"
"/aws/service/global-infrastructure/regions/eu-west-1"
"/aws/service/global-infrastructure/regions/eu-west-3"
"/aws/service/global-infrastructure/regions/sa-east-1"
"/aws/service/global-infrastructure/regions/us-east-2"
"/aws/service/global-infrastructure/regions/us-gov-east-1"
"/aws/service/global-infrastructure/regions/us-gov-west-1"
"/aws/service/global-infrastructure/regions/us-west-1"
"/aws/service/global-infrastructure/regions/ap-northeast-2"
"/aws/service/global-infrastructure/regions/ap-northeast-3"
"/aws/service/global-infrastructure/regions/ap-south-1"
"/aws/service/global-infrastructure/regions/ap-southeast-1"
"/aws/service/global-infrastructure/regions/ap-southeast-2"
"/aws/service/global-infrastructure/regions/ca-central-1"
"/aws/service/global-infrastructure/regions/cn-north-1"
"/aws/service/global-infrastructure/regions/cn-northwest-1"
"/aws/service/global-infrastructure/regions/eu-west-2"
"/aws/service/global-infrastructure/regions/us-west-2"
"/aws/service/global-infrastructure/regions/us-east-1"

您可以使用以下命令查看所有可用 AWS 服务的完整列表,并将其按字母顺序排序。此示例输出已由于空间问题截断。

aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/services --query Parameters[].Name | sort

此命令会返回如下信息。

"/aws/service/global-infrastructure/services/acm-pca",
    "/aws/service/global-infrastructure/services/acm",
    "/aws/service/global-infrastructure/services/alexaforbusiness",
    "/aws/service/global-infrastructure/services/apigateway",
    "/aws/service/global-infrastructure/services/application-autoscaling",
    "/aws/service/global-infrastructure/services/appmesh",
    "/aws/service/global-infrastructure/services/appstream",
    "/aws/service/global-infrastructure/services/appsync",
    "/aws/service/global-infrastructure/services/athena",
    "/aws/service/global-infrastructure/services/autoscaling-plans",
    "/aws/service/global-infrastructure/services/autoscaling",
    "/aws/service/global-infrastructure/services/backup",
    "/aws/service/global-infrastructure/services/batch",
    "/aws/service/global-infrastructure/services/budgets",
    "/aws/service/global-infrastructure/services/ce",
    "/aws/service/global-infrastructure/services/chime",
    "/aws/service/global-infrastructure/services/cloud9",
    "/aws/service/global-infrastructure/services/cloudformation",
    "/aws/service/global-infrastructure/services/cloudfront",
    "/aws/service/global-infrastructure/services/cloudhsm",
    "/aws/service/global-infrastructure/services/cloudhsmv2",
    "/aws/service/global-infrastructure/services/cloudsearch",
    "/aws/service/global-infrastructure/services/cloudtrail",
    "/aws/service/global-infrastructure/services/cloudwatch",
    "/aws/service/global-infrastructure/services/codebuild",

您可以查看服务可用区域的列表。此示例使用 Systems Manager (ssm)。

aws ssm get-parameters-by-path --path /aws/service/global-infrastructure/services/ssm/regions --query Parameters[].Value

此命令会返回如下信息。

[
    "ap-east-1",
    "ap-northeast-2",
    "ap-south-1",
    "ca-central-1",
    "cn-northwest-1",
    "eu-west-2",
    "sa-east-1",
    "us-east-2",
    "us-gov-east-1",
    "us-west-2",
    "ap-northeast-1",
    "ap-southeast-1",
    "ap-southeast-2",
    "cn-north-1",
    "eu-central-1",
    "eu-north-1",
    "eu-west-1",
    "us-east-1",
    "us-gov-west-1",
    "us-west-1",
    "eu-west-3"
]

您可以使用以下命令查看服务的区域终端节点。

aws ssm get-parameter --name /aws/service/global-infrastructure/regions/us-west-1/services/ssm/endpoint --query Parameter.Value

此命令会返回如下信息。

"ssm.us-west-1.amazonaws.com"