本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
的後續處理範本檔案 AWS Proton
準備環境和服務基礎設施做為程式碼 (IaC) 檔案及其個別結構描述檔案之後,您必須將它們整理在目錄中。您也必須建立資訊清單 YAML 檔案。資訊清單檔案會列出目錄中的 IaC 檔案、轉譯引擎,以及用於在此範本中開發 IaC 的範本語言。
注意
資訊清單檔案也可以獨立於範本套件使用,做為直接定義元件的直接輸入。在這種情況下,它一律會為 CloudFormation 和 Terraform 指定單一 IaC 範本檔案。如需元件的詳細資訊,請參閱 AWS Proton 元件。
資訊清單檔案需要遵循下列範例中顯示的格式和內容。
CloudFormation 資訊清單檔案格式:
使用 CloudFormation,您可以列出單一檔案。
infrastructure: templates: - file: "cloudformation.yaml" rendering_engine: jinja template_language: cloudformation
Terraform 資訊清單檔案格式:
透過 terraform,您可以明確列出單一檔案,或使用萬用字元*
列出目錄中的每個檔案。
注意
萬用字元只包含名稱結尾為 的檔案.tf
。會忽略其他檔案。
infrastructure: templates: - file: "*" rendering_engine: hcl template_language: terraform
CodeBuild 型佈建資訊清單檔案格式:
使用 CodeBuild 型佈建,您可以指定佈建和取消佈建 shell 命令。
注意
除了資訊清單之外,您的套件還應該包含命令依賴的任何檔案。
下列範例資訊清單使用 CodeBuild 型佈建來使用 () 佈建 AWS Cloud Development Kit (AWS CDK) (部署) 和取消佈建 (還原) 資源AWS CDK。範本套件也應包含 CDK 程式碼。
在佈建期間,AWS Proton 會建立輸入檔案,其中包含您在範本結構描述中以名稱 定義的輸入參數值proton-input.json
。
infrastructure: templates: - rendering_engine: codebuild settings: image: aws/codebuild/amazonlinux2-x86_64-standard:4.0 runtimes: nodejs: 16 provision: - npm install - npm run build - npm run cdk bootstrap - npm run cdk deploy -- --require-approval never --outputs-file proton-outputs.json - jq 'to_entries | map_values(.value) | add | to_entries | map({key:.key, valueString:.value})' < proton-outputs.json > outputs.json - aws proton notify-resource-deployment-status-change --resource-arn $RESOURCE_ARN --status IN_PROGRESS --outputs file://./outputs.json deprovision: - npm install - npm run build - npm run cdk destroy project_properties: VpcConfig: VpcId: "{{ environment.inputs.codebuild_vpc_id }}" Subnets: "{{ environment.inputs.codebuild_subnets }}" SecurityGroupIds: "{{ environment.inputs.codebuild_security_groups }}"
為您的環境或服務範本套件設定目錄和資訊清單檔案之後,您可以將目錄壓縮為 tar 球,並將其上傳至 Amazon Simple Storage Service (Amazon S3) 儲存貯體,其中 AWS Proton 可以擷取它們,或範本同步 Git 儲存庫。
當您建立 環境的次要版本或註冊的服務範本時 AWS Proton,您會提供位於 S3 儲存貯體中環境或服務範本套件 tar 球的路徑。 AWS Proton 會使用新的範本次要版本儲存它。您可以選擇新的範本次要版本來建立或更新環境或服務 AWS Proton。
環境範本套件包裝
您建立的環境範本套件有兩種類型 AWS Proton。
-
若要為標準環境範本建立環境範本套件,請在目錄中組織結構描述、基礎設施即程式碼 (IaC) 檔案和資訊清單檔案,如下列環境範本套件目錄結構所示。
-
若要為客戶受管環境範本建立環境範本套件,請僅提供結構描述檔案和目錄。請勿包含基礎設施目錄和檔案。如果包含基礎設施目錄和檔案, 會 AWS Proton 擲回錯誤。
如需詳細資訊,請參閱註冊和發佈範本。
CloudFormation 環境範本套件目錄結構:
/schema schema.yaml /infrastructure manifest.yaml cloudformation.yaml
Terraform 環境範本套件目錄結構:
/schema schema.yaml /infrastructure manifest.yaml environment.tf
服務範本套件後續處理
若要建立服務範本套件,您必須將結構描述、基礎設施即程式碼 (IaC) 檔案和資訊清單檔案組織到目錄中,如服務範本套件目錄結構範例所示。
如果您在範本套件中不包含服務管道,請勿包含管道目錄和檔案,並在建立要與此範本套件相關聯的服務範本"pipelineProvisioning": "CUSTOMER_MANAGED"
時設定 和 。
注意
建立服務範本pipelineProvisioning
後,您無法修改 。
如需詳細資訊,請參閱註冊和發佈範本。
CloudFormation 服務範本套件目錄結構:
/schema schema.yaml /instance_infrastructure manifest.yaml cloudformation.yaml /pipeline_infrastructure manifest.yaml cloudformation.yaml
Terraform 服務範本套件目錄結構:
/schema schema.yaml /instance_infrastructure manifest.yaml instance.tf /pipeline_infrastructure manifest.yaml pipeline.tf