結構描述檔案 - AWS Proton

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

結構描述檔案

身為管理員,當您使用 Open API Data Models (結構描述) 區段來定義範本套件的參數結構描述 YAML 檔案時, AWS Proton 可以根據您在結構描述中定義的需求驗證參數值輸入。

如需格式和可用關鍵字的詳細資訊,請參閱 OpenAPI 的結構描述物件區段。

環境範本套件的結構描述需求

您的結構描述必須遵循 YAML 格式 OpenAPI 的資料模型 (結構描述) 區段。它也必須是環境範本套件的一部分。

對於您的環境結構描述,您必須包含格式化的標頭,以確定您正在使用 Open API 的資料模型 (結構描述) 區段。在下列環境結構描述範例中,這些標頭會出現在前三行中。

environment_input_type 必須包含並定義您提供的名稱。在下列範例中,這在第 5 行定義。透過定義此參數,您可以將其與 AWS Proton 環境資源建立關聯。

若要遵循 Open API 結構描述模型,您必須包含 types。在下列範例中,這是第 6 行。

在 之後types,您必須定義 environment_input_type類型。您可以將環境的輸入參數定義為 的屬性environment_input_type。您必須包含至少一個名稱與環境基礎設施中列出的至少一個參數相符的屬性,做為與結構描述相關聯的程式碼 (IaC) 檔案。

當您建立環境並提供自訂參數值時, AWS Proton 會使用結構描述檔案來比對、驗證和插入至相關聯 CloudFormation IaC 檔案中的大括號參數。針對每個屬性 (參數),提供 nametype。或者,您也可以提供 descriptiondefaultpattern

下列範例標準環境範本結構描述的定義參數包括 vpc_cidr、 和 subnet_one_cidrsubnet_two_cidr以及default關鍵字和預設值。當您使用此環境範本套件結構描述建立環境時,您可以接受預設值或提供自己的值。如果參數沒有預設值並列為required屬性 (參數),您必須在建立環境時為其提供值。

第二個範例標準環境範本結構描述會列出 required 參數 my_other_sample_input

您可以為兩種類型的環境範本建立結構描述。如需詳細資訊,請參閱註冊和發佈範本

  • 標準環境範本

    在下列範例中,使用描述和輸入屬性定義環境輸入類型。此結構描述範例可與範例 3 中顯示的 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 輸出。您只需要將輸出值類型定義為字串 (而非清單、陣列或其他類型)。例如,下一個程式碼片段會顯示外部 AWS CloudFormation 範本的輸出區段。這是來自範例 1 中顯示的範本。它可用於為從範例 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" [...]

服務範本套件的結構描述需求

您的結構描述必須遵循 YAML 格式 OpenAPI 的資料模型 (結構描述) 區段,如下列範例所示。您必須在服務範本套件中提供結構描述檔案。

在下列服務結構描述範例中,您必須包含格式化的標頭。在下列範例中,這位於前三行。這是為了確認您使用的是 Open API 的資料模型 (結構描述) 區段。

service_input_type 必須包含並定義您提供的名稱。在下列範例中,這是第 5 行。這會將參數與服務 AWS Proton 資源建立關聯。

當您使用主控台或 CLI 建立 AWS Proton 服務時,預設會包含服務管道。當您包含服務的服務管道時,您必須pipeline_input_type包含您提供的名稱。在下列範例中,這是第 7 行。如果您包含 AWS Proton 服務管道,請勿包含此參數。如需詳細資訊,請參閱註冊和發佈範本

若要遵循 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 檔案的大括號參數。針對每個屬性 (參數),提供 nametype。或者,也提供 descriptiondefaultpattern

範例結構描述的定義參數包括 porttask_sizedesired_countimage以及default關鍵字和預設值。當您使用此服務範本套件結構描述建立服務時,您可以接受預設值或提供自己的值。參數unique_name也包含在範例中,而且沒有預設值。它被列為required屬性 (參數)。身為管理員或開發人員,您必須在建立服務時提供required參數的值。

如果您想要使用服務管道建立服務範本,請在結構描述pipeline_input_type中包含 。

包含 服務 AWS Proton 管道之服務的服務結構描述檔案範例。

此結構描述範例可與範例 4 範例 5 中顯示的 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"