

终止支持通知：2026 年 10 月 7 日， AWS 将终止对的支持。 AWS Proton 2026 年 10 月 7 日之后，您将无法再访问 AWS Proton 控制台或 AWS Proton 资源。您部署的基础架构将保持不变。有关更多信息，请参阅《[AWS Proton 服务弃用和迁移指南》](https://docs.aws.amazon.com/proton/latest/userguide/proton-end-of-support.html)。

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

# 架构文件
<a name="ag-schema"></a>

作为管理员，当您使用 Open API [数据模型（架构）部分](https://swagger.io/docs/specification/data-models/)为模板包定义参数架构 YAML 文件时， AWS Proton 可以根据您在架构中定义的要求验证参数值输入。

有关格式和可用关键字的更多信息，请参阅 OpenAPI 的 [Schema object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#schemaObject) 部分。

## 环境模板捆绑包的架构要求
<a name="schema-req-env"></a>

您的架构必须遵循 OpenAPI 的 [Data Models (schemas) 部分](https://swagger.io/docs/specification/data-models/)并采用 YAML 格式。它还必须是您的环境模板捆绑包的一部分。

对于您的环境架构，您必须包含设置了格式的标头，以确认您使用了 Open API 的 Data Models (schemas) 部分。在以下环境架构示例中，这些标头出现在前三行中。

必须包含 `environment_input_type` 并使用您提供的名称进行定义。在以下示例中，这是在第 5 行中定义的。通过定义此参数，可以将其与 AWS Proton 环境资源相关联。

要遵循 Open API 架构模型，您必须包含 `types`。在以下示例中，它位于第 6 行。

在 `types` 后面，您必须定义一个 `environment_input_type` 类型。您将环境的输入参数定义为 `environment_input_type` 的属性。您必须包含至少一个属性，其名称至少与架构的关联环境基础设施即代码 (IaC) 文件中列出的一个参数匹配。

创建环境并提供自定义参数值时，会 AWS Proton 使用架构文件进行匹配、验证并将其注入关联的 CloudFormation IaC 文件中的花括号参数中。对于每个属性（参数），提供 `name` 和 `type`。（可选）还提供 `description`、`default` 和 `pattern`。

为以下示例*标准* 环境模板架构定义的参数包括 `vpc_cidr`、`subnet_one_cidr` 和 `subnet_two_cidr`，它们使用 `default` 关键字和默认值。在您使用该环境模板捆绑包架构创建环境时，您可以接受默认值或提供您自己的值。如果参数*没有* 默认值并且作为 `required` 属性（参数）列出，您在创建环境时必须为其提供值。

第二个示例*标准* 环境模板架构列出了 `required` 参数 `my_other_sample_input`。

您可以为两种类型的环境模板创建一个架构。有关更多信息，请参阅 [注册并发布模板](template-create.md)。
+ ***标准* 环境模板**

  在以下示例中，环境输入类型是使用描述和输入属性定义的。此架构示例可以与示[例 3](ag-infrastructure-tmp-files-cloudformation.md#ag-proton-env-cfn-example) 中所示的 AWS Proton CloudFormation IaC 文件一起使用。

  *标准* 环境模板的示例架构：

  ```
  schema:                            # required
    format:                          # required
      openapi: "3.0.0"               # required
    # required              defined by administrator
    environment_input_type: "PublicEnvironmentInput"
    types:                           # required
      # defined by administrator
      PublicEnvironmentInput:
        type: object
        description: "Input properties for my environment"
        properties:
          vpc_cidr:                   # parameter
            type: string
            description: "This CIDR range for your VPC"
            default: 10.0.0.0/16
            pattern: ([0-9]{1,3}\.){3}[0-9]{1,3}($|/(16|24))
          subnet_one_cidr:            # parameter
            type: string
            description: "The CIDR range for subnet one"
            default: 10.0.0.0/24
            pattern: ([0-9]{1,3}\.){3}[0-9]{1,3}($|/(16|24))
          subnet_two_cidr:            # parameter
            type: string
            description: "The CIDR range for subnet one"
            default: 10.0.1.0/24
            pattern: ([0-9]{1,3}\.){3}[0-9]{1,3}($|/(16|24))
  ```

  包含 `required` 参数的*标准* 环境模板的示例架构：

  ```
  schema:                            # required
    format:                          # required
      openapi: "3.0.0"               # required
    # required              defined by administrator
    environment_input_type: "MyEnvironmentInputType"
    types:                           # required
      # defined by administrator
      MyEnvironmentInputType:
        type: object
        description: "Input properties for my environment"
        properties:
          my_sample_input:           # parameter
            type: string
            description: "This is a sample input"
            default: "hello world"
          my_other_sample_input:     # parameter
            type: string
            description: "Another sample input"
          another_optional_input:    # parameter
            type: string
            description: "Another optional input"
            default: "!"
        required:
          - my_other_sample_input
  ```
+ ***客户托管* 环境模板**

  在以下示例中，架构仅包含输出列表，这些输出复制您用于预置*客户托管* 基础设施的 IaC 的输出。您需要将输出值类型仅定义为*字符串*（而*不能* 定义为列表、数组或其他类型）。例如，下一个代码片段显示了外部 CloudFormation 模板的输出部分。它来自于[示例 1](ag-infrastructure-tmp-files-cloudformation.md#ag-env-cfn-example) 中所示的模板。它可用于为根据[示例](ag-infrastructure-tmp-files-cloudformation.md#ag-proton-svc-cfn-example) 4 创建的 AWS Proton Fargate 服务创建外部*客户托管*基础架构。
**重要**  
作为管理员，您必须确保您的预配置和托管基础设施以及所有输出参数都与相关的*客户托管*环境模板兼容。 AWS Proton 无法代表你解释更改，因为这些更改对他们不可见 AWS Proton。不一致会导致失败。

  *客户托管*环境模板的 CloudFormation IaC 文件输出示例：

  ```
  // Cloudformation Template Outputs
  [...]
  Outputs:
    ClusterName:
      Description: The name of the ECS cluster
      Value: !Ref 'ECSCluster'
    ECSTaskExecutionRole:
      Description: The ARN of the ECS role
      Value: !GetAtt 'ECSTaskExecutionRole.Arn'
    VpcId:
      Description: The ID of the VPC that this stack is deployed in
      Value: !Ref 'VPC'
  [...]
  ```

  以下示例显示了相应的 AWS Proton *客户托管*环境模板包的架构。每个输出值定义为一个字符串。

  *客户托管* 环境模板的示例架构：

  ```
  schema:                            # required
    format:                          # required
      openapi: "3.0.0"               # required
    # required              defined by administrator
    environment_input_type: "EnvironmentOutput"
    types:                           # required
      # defined by administrator
      EnvironmentOutput:
        type: object
        description: "Outputs of the environment"
        properties:
          ClusterName:               # parameter
            type: string
            description: "The name of the ECS cluster"
          ECSTaskExecutionRole:      # parameter
            type: string
            description: "The ARN of the ECS role"
          VpcId:                     # parameter
            type: string
            description: "The ID of the VPC that this stack is deployed in"
  [...]
  ```

## 服务模板捆绑包的架构要求
<a name="schema-req-svc"></a>

您的架构必须遵循 OpenAPI 的 [Data Models (schemas) 部分](https://swagger.io/docs/specification/data-models/)并采用 YAML 格式，如以下示例中所示。您必须在服务模板捆绑包中提供架构文件。

在以下服务架构示例中，您必须包含设置了格式的标头。在以下示例中，它位于前三行。这是为了确认您使用了 Open API 的 Data Models (schemas) 部分。

必须包含 `service_input_type` 并使用您提供的名称进行定义。在以下示例中，它位于第 5 行。这会将参数与 AWS Proton 服务资源相关联。

当您使用控制台或 CLI 创建 AWS Proton 服务时，默认情况下会包含服务管道。在您为服务包含服务管道时，您必须包含 `pipeline_input_type` 并具有您提供的名称。在以下示例中，它位于第 7 行。如果您@@ *不**包括 AWS Proton 服务管道，请不要*包含此参数。有关更多信息，请参阅 [注册并发布模板](template-create.md)。

要遵循 Open API 架构模型，您必须在以下示例中包含 `types`，它位于第 9 行。

在 `types` 后面，您必须定义一个 `service_input_type` 类型。您将服务的输入参数定义为 `service_input_type` 的属性。您必须包含至少一个属性，其名称至少与架构的关联服务基础设施即代码 (IaC) 文件中列出的一个参数匹配。

要定义服务管道，您必须在 `service_input_type` 定义下面定义一个 `pipeline_input_type`。如上所述，您必须包含至少一个属性，其名称至少与架构的关联管道 IaC 文件中列出的一个参数匹配。如果您@@ *不**包括 AWS Proton 服务管道，请不要*包含此定义。

作为管理员或开发人员，当您创建服务并提供自定义参数值时，会 AWS Proton 使用架构文件来匹配、验证这些值，并将其注入关联的 CloudFormation IaC 文件的花括号参数中。对于每个属性（参数），提供 `name` 和 `type`。（可选）还提供 `description`、`default` 和 `pattern`。

为示例模式定义的参数包括 `port`、`desired_count`、`task_size` 和 `image`，它们使用 `default` 关键字和默认值。在您使用该服务模板捆绑包架构创建服务时，您可以接受默认值或提供您自己的值。`unique_name` 参数也包含在该示例中，并且*没有* 默认值。它作为 `required` 属性（参数）列出。作为管理员或开发人员，您在创建服务时必须提供 `required` 参数的值。

如果要创建具有服务管道的服务模板，请将 `pipeline_input_type` 包含在架构中。

**包含服务管道的服务的示例 AWS Proton 服务架构文件。**

 此架构示例可以与示例 [4 和示例](ag-infrastructure-tmp-files-cloudformation.md#ag-proton-svc-cfn-example) [5](ag-infrastructure-tmp-files-cloudformation.md#ag-proton-pipeline-cfn-example) 中所示的 AWS Proton IaC 文件一起使用。包含一个服务管道。

```
schema:                            # required
  format:                          # required
    openapi: "3.0.0"               # required
  # required           defined by administrator
  service_input_type: "LoadBalancedServiceInput"
  # only include if including AWS Proton service pipeline, defined by administrator
  pipeline_input_type: "PipelineInputs"

  types:                           # required
    # defined by administrator
    LoadBalancedServiceInput:
      type: object
      description: "Input properties for a loadbalanced Fargate service"
      properties:
        port:                      # parameter
          type: number
          description: "The port to route traffic to"
          default: 80
          minimum: 0
          maximum: 65535
        desired_count:             # parameter
          type: number
          description: "The default number of Fargate tasks you want running"
          default: 1
          minimum: 1
        task_size:                 # parameter
          type: string
          description: "The size of the task you want to run"
          enum: ["x-small", "small", "medium", "large", "x-large"]
          default: "x-small"
        image:                     # parameter
          type: string
          description: "The name/url of the container image"
          default: "public.ecr.aws/z9d2n7e1/nginx:1.19.5"
          minLength: 1
          maxLength: 200
        unique_name:               # parameter
          type: string
          description: "The unique name of your service identifier. This will be used to name your log group, task definition and ECS service"
          minLength: 1
          maxLength: 100
      required:
        - unique_name
    # defined by administrator
    PipelineInputs:
      type: object
      description: "Pipeline input properties"
      properties:
        dockerfile:                # parameter
          type: string
          description: "The location of the Dockerfile to build"
          default: "Dockerfile"
          minLength: 1
          maxLength: 100
        unit_test_command:         # parameter
          type: string
          description: "The command to run to unit test the application code"
          default: "echo 'add your unit test command here'"
          minLength: 1
          maxLength: 200
```

如果要创建没有服务管道的服务模板，请*不要* 将 `pipeline_input_type` 包含在架构中，如以下示例中所示。

***不*包含服务管道的服务的示例 AWS Proton 服务架构文件**

```
schema:                            # required
  format:                          # required
    openapi: "3.0.0"               # required
  # required            defined by administrator  
  service_input_type: "MyServiceInstanceInputType"

  types:                           # required
    # defined by administrator
    MyServiceInstanceInputType:
      type: object
      description: "Service instance input properties"
      required:
        - my_sample_service_instance_required_input
      properties:
        my_sample_service_instance_optional_input:   # parameter
          type: string
          description: "This is a sample input"
          default: "hello world"
        my_sample_service_instance_required_input:   # parameter
          type: string
          description: "Another sample input"
```