本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Service CloudFormation IaC 檔案參數詳細資訊和範例
您可以在服務和管道基礎設施中將參數定義為程式碼 (IaC) 檔案並加以參考。如需參數、參數類型、參數命名空間,以及如何在 IaC 檔案中使用參數的 AWS Proton 詳細說明,請參閱 AWS Proton 參數。
定義服務參數
您可以定義服務 IaC 檔案的輸入和輸出參數。
讀取服務 IaC 檔案中的參數值
您可以讀取與服務 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 檔案範例
下列範例是來自服務 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