

終止支援通知：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)。

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

# Service CloudFormation IaC 檔案參數詳細資訊和範例
<a name="svc-parameters"></a>

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

## 定義服務參數
<a name="svc-parameters.define"></a>

您可以定義服務 IaC 檔案的輸入和輸出參數。
+ **輸入參數** – 在[結構描述檔案中](ag-schema.md)定義服務執行個體輸入參數。

  下列清單包含典型使用案例的服務輸入參數範例。
  + 連接埠
  + 任務大小
  + 映像
  + 所需計數
  + Docker 檔案
  + 單位測試命令

  [您在建立服務](ag-create-svc.md)時提供輸入參數的值：
  + 使用 主控台填寫 AWS Proton 提供的結構描述型表單。
  + 使用 CLI 提供包含值的規格。
+ **輸出參數** – 在服務 IaC 檔案中定義服務執行個體輸出。然後，您可以在其他資源的 IaC 檔案中參考這些輸出。

## 讀取服務 IaC 檔案中的參數值
<a name="svc-parameters.refer"></a>

您可以讀取與服務 IaC 檔案中其他資源相關的參數。您可以在參數命名空間中參考參數的名稱來讀取 AWS Proton 參數值。
+ **輸入參數** – 參考 讀取服務執行個體輸入值`service_instance.inputs.input-name`。
+ **資源參數** – 透過參考 `service.name`、 `service_instance.name`和 等名稱讀取 AWS Proton 資源參數`environment.name`。
+ **輸出參數** – 透過參考 `environment.outputs.output-name`或 讀取其他資源的輸出`service_instance.components.default.outputs.output-name`。

## 具有參數的服務 IaC 檔案範例
<a name="svc-parameters.example"></a>

下列範例是來自服務 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
```