Service CloudFormation IaC 檔案參數詳細資訊和範例 - AWS Proton

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

Service CloudFormation IaC 檔案參數詳細資訊和範例

您可以在服務和管道基礎設施中將參數定義為程式碼 (IaC) 檔案並加以參考。如需參數、參數類型、參數命名空間,以及如何在 IaC 檔案中使用參數的 AWS Proton 詳細說明,請參閱 AWS Proton 參數

定義服務參數

您可以定義服務 IaC 檔案的輸入和輸出參數。

  • 輸入參數 – 在結構描述檔案中定義服務執行個體輸入參數。

    下列清單包含典型使用案例的服務輸入參數範例。

    • 連線埠

    • 任務大小

    • 映像

    • 所需計數

    • Docker 檔案

    • 單位測試命令

    您在建立服務時提供輸入參數的值:

    • 使用 主控台填寫 AWS Proton 提供的結構描述型表單。

    • 使用 CLI 提供包含值的規格。

  • 輸出參數 – 在服務 IaC 檔案中定義服務執行個體輸出。然後,您可以在其他資源的 IaC 檔案中參考這些輸出。

讀取服務 IaC 檔案中的參數值

您可以讀取與服務 IaC 檔案中其他資源相關的參數。您可以在參數命名空間中參考參數的名稱來讀取 AWS Proton 參數值。

  • 輸入參數 – 參考 讀取服務執行個體輸入值service_instance.inputs.input-name

  • 資源參數 – 透過參考 service.nameservice_instance.name和 等名稱讀取 AWS Proton 資源參數environment.name

  • 輸出參數 – 透過參考 environment.outputs.output-name或 讀取其他資源的輸出service_instance.components.default.outputs.output-name

具有參數的服務 IaC 檔案範例

下列範例是來自服務 CloudFormation IaC 檔案的程式碼片段。environment.outputs. 命名空間是指來自環境 IaC 檔案的輸出。service_instance.inputs. 命名空間是指服務執行個體輸入參數。service_instance.name 屬性是指 AWS Proton 資源參數。

Resources: StoreServiceInstanceInputValue: Type: AWS::SSM::Parameter Properties: Type: String Value: "{{ service.name }} {{ service_instance.name }} {{ service_instance.inputs.my_sample_service_instance_required_input }} {{ service_instance.inputs.my_sample_service_instance_optional_input }} {{ environment.outputs.MySampleInputValue }} {{ environment.outputs.MyOtherSampleInputValue }}" # resource parameter references # input parameter references # output references to an environment infrastructure as code file Outputs: MyServiceInstanceParameter: # output definition Value: !Ref StoreServiceInstanceInputValue MyServiceInstanceRequiredInputValue: # output definition Value: "{{ service_instance.inputs.my_sample_service_instance_required_input }}" # input parameter reference MyServiceInstanceOptionalInputValue: # output definition Value: "{{ service_instance.inputs.my_sample_service_instance_optional_input }}" # input parameter reference MyServiceInstancesEnvironmentSampleOutputValue: # output definition Value: "{{ environment.outputs.MySampleInputValue }}" # output reference to an environment IaC file MyServiceInstancesEnvironmentOtherSampleOutputValue: # output definition Value: "{{ environment.outputs.MyOtherSampleInputValue }}" # output reference to an environment IaC file