本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
設定企業藍圖工廠
本節可協助您在 AWS 環境中設定企業藍圖工廠。它包含設定企業藍圖工廠所需儲存庫和資源 AWS 的詳細說明。
先決條件
以下是在您的 AWS 環境中設定企業藍圖工廠的先決條件:
-
下列項目 AWS 帳戶:
-
用來管理企業藍圖工廠和發行產品的帳戶
-
一或多個使用已發行產品的帳戶
-
-
所有帳戶皆為:
-
在 中以組織身分受管 AWS Organizations
-
位於相同的組織單位 (OU)
-
-
部署可建立下列 AWS 資源之 AWS CloudFormation 堆疊的許可:
-
Amazon CloudWatch Logs 日誌群組
-
AWS CodePipeline 管道
-
AWS CodeBuild 專案
-
Amazon EventBridge 事件匯流排政策和規則
-
AWS Identity and Access Management (IAM) 角色和政策
-
AWS Key Management Service (AWS KMS) 金鑰和金鑰政策
-
AWS Service Catalog 產品組合、產品和佈建產品
-
Amazon Simple Notification Service (Amazon SNS) 主題、主題政策和訂閱
-
Amazon Simple Storage Service (Amazon S3) 儲存貯體
-
AWS Systems Manager 參數存放區參數
如需設定這些許可的詳細資訊,請參閱 CloudFormation 文件和實作最低權限許可的政策 AWS CloudFormation。
-
-
GitHub 帳戶
最佳實務
我們建議您在 AWS 環境中設定企業藍圖工廠時遵循以下最佳實務:
建立儲存庫
本節可協助您設定 企業藍圖工廠的組態儲存庫和產品儲存庫。若要設定儲存庫,您可以在 GitHub 中放棄
分支 GitHub 儲存庫
建立 CodeConnections 連線
-
在 AWS CLI 中,輸入下列命令以建立與 GitHub 的 CodeConnections 連線:
aws codeconnections create-connection --provider-type GitHub --connection-name <MyConnection> -
使用 AWS 開發人員工具主控台來完成連線。如需詳細資訊,請參閱更新待定連線。
複製分叉儲存庫
-
輸入下列命令,將 GitHub 儲存庫複製到您的本機工作站:
git clone git@github.com:<user>/aws-enterprise-blueprint-factory-config-repo ServiceCatalog-ConfigRepo git clone git@github.com:<user>/aws-enterprise-blueprint-factory-blueprint-repo ServiceCatalog-BlueprintProductRepo git clone git@github.com:<user>/aws-enterprise-blueprint-factory-code-repo ServiceCatalog-CodeRepo
設定企業藍圖工廠
本節中的指示說明如何在目標帳戶中設定企業藍圖工廠。您從 GitHub 複製的產品儲存庫包含兩個範例 CloudFormation 範本,BP-S3以及 BP-SNS。遵循這些指示,即可將這兩個範例藍圖部署為 Service Catalog 中的產品。
設定角色
-
在藍圖開發人員的帳戶中,建立下列信任政策,然後將其儲存為
sc-enduserrole-trust-policy.json:{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:role/ServiceCatalogEndUserRole" }, "Action": "sts:AssumeRole" } } -
輸入下列命令來建立 IAM
ServiceCatalogEndUserRole角色:aws iam create-role \ --role-name ServiceCatalogEndUserRole \ --assume-role-policy-document file://sc-enduserrole-trust-policy.json aws iam attach-role-policy \ --policy-arn arn:aws:iam::aws:policy/AWSServiceCatalogEndUserFullAccess \ -- role-name ServiceCatalogEndUserRole注意
開發人員使用
ServiceCatalogEndUserRole角色來佈建 Service Catalog 產品。此角色不需要許可即可建立藍圖中定義的資源。這遵循最低權限許可和職責分離的最佳實務。 -
建立下列信任政策,然後將其儲存為
sc-launchconstraintrole-trust-policy.json:{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Principal": { "Service": "servicecatalog.amazonaws.com" }, "Action": "sts:AssumeRole" } } -
輸入下列命令來建立 IAM
ServiceCataloglogLaunchConstraintRole角色:aws iam create-role \ --role-name ServiceCataloglogLaunchConstraintRole \ --assume-role-policy-document file://sc-launchconstraintrole-trust-policy.json aws iam attach-role-policy \ --policy-arn arn:aws:iam::aws:policy/AmazonSNSFullAccess \ --role-name ServiceCataloglogLaunchConstraintRole aws iam attach-role-policy \ --policy-arn arn:aws:iam::aws:policy/AWSCloudFormationFullAccess \ --role-name ServiceCataloglogLaunchConstraintRole -
將下列政策新增至 IAM
ServiceCataloglogLaunchConstraintRole角色。如 Service Catalog 文件中的設定啟動角色所述,包含產品資源所需的任何其他許可:{ "Statement":[ { "Effect":"Allow", "Action":[ "s3:GetObject" ], "Resource":"*", "Condition":{ "StringEquals":{ "s3:ExistingObjectTag/servicecatalog:provisioning":"true" } } ] }注意
Service Catalog 使用此角色將 CloudFormation 堆疊部署為 Service Catalog 中的產品。此角色的信任政策可確保只有 Service Catalog 可以擔任該角色。其他使用者或服務無法擔任此角色。這遵循職責分離的最佳實務。
-
建立下列信任政策,然後將其儲存為
sc-codebuild-trust-policy.json:{ "Version": "2012-10-17", "Statement": { "Effect": "Allow", "Principal": { "Service": "codebuild.amazonaws.com" }, "Action": "sts:AssumeRole" } } -
輸入下列命令來建立 IAM
codebuild-servicecatalog-admin-role角色:aws iam create-role \ --role-name codebuild-servicecatalog-admin-role \ --assume-role-policy-document file://sc-codebuild-trust-policy.json aws iam attach-role-policy \ --policy-arn arn:aws:iam::aws:policy/AWSCodeBuildAdminAccess \ --role-name codebuild-servicecatalog-admin-role注意
組態管道中的 CodeBuild 任務使用此角色。
設定 Amazon S3 儲存貯體
-
若要建立用於存放 CodePipeline 成品的 Amazon Simple Storage Service (Amazon S3) 儲存貯體,請遵循 Amazon S3 文件中建立儲存貯體的指示。請遵循 Amazon S3 的安全最佳實務。
設定 AWS Systems Manager 參數
-
請依照 Systems Manager 中建立參數存放區參數的指示,在下表中建立 Systems Manager 參數。這些參數用於部署組態管道的 CloudFormation 範本。
參數名稱 類型 描述 /blueprints/resources/vpc_id字串 存放目標虛擬私有雲端 (VPC) ID 的參數。 /blueprints/resources/subnetsStringList 存放目標子網路 IDs參數。 /blueprints/resources/securitygroupsStringList 存放目標安全群組 IDs的參數。 /blueprints/resources/artifacts-bucket-name字串 存放用於 CodePipeline 成品之 Amazon S3 儲存貯體名稱的參數。 /blueprints/resources/BlueprintRepo字串 存放儲存企業藍圖工廠藍圖之 GitHub 儲存庫的參數。預設值為 <user>/aws-enterprise-blueprint-factory-blueprint-repo。/blueprints/resources/CodeRepo字串 存放 GitHub 儲存庫的參數,用於存放企業藍圖工廠組態管道程式碼和 Bootstrapping-Admin-Product程式碼。預設值為<user>/aws-enterprise-blueprint-factory-code-repo。/blueprints/resources/ConfigRepo字串 存放儲存企業藍圖工廠組態檔案之 GitHub 儲存庫的參數。預設值為 <user>/aws-enterprise-blueprint-factory-config-repo。
更新 CloudFormation 範本
-
在程式碼儲存庫 (
ServiceCatalog-CodeRepo) 中,開啟 ServiceCatalog-Pipeline.yml 檔案。 -
編輯此檔案中下列參數的預設值:
-
ConfigRepositoryName是 Systems Manager 參數,存放儲存企業藍圖工廠組態檔案的 GitHub 儲存庫。預設值為/blueprints/resources/ConfigRepo。 -
CodeRepositoryName是 Systems Manager 參數,用於存放 GitHub 儲存庫,其中存放 Enterprise Blueprint Factory 組態管道程式碼和Bootstrapping-Admin-Product程式碼。預設值為/blueprints/resources/CodeRepo。 -
BlueprintRepositoryName是 Systems Manager 參數,存放儲存企業藍圖工廠藍圖的 GitHub 儲存庫。預設值為/blueprints/resources/BlueprintRepo。 -
BranchName是存放組態檔案之組態儲存庫的分支。預設值為main。 -
VPCID是 Systems Manager 參數,存放目標 VPC 的 ID。預設值為/blueprints/resources/vpc_id。 -
Subnets是 Systems Manager 參數,可存放目標子網路IDs。預設值為/blueprints/resources/subnets。 -
SecurityGroupIds是 Systems Manager 參數,存放目標安全群組IDs。預設值為/blueprints/resources/securitygroups。 -
IamRoleName是 CodeBuild 任務使用的 IAM 角色名稱。預設值為codebuild-servicecatalog-admin-role。 -
EnvironmentType是您部署企業藍圖工廠的環境。預設值為DEV。 -
ArtifactBucket是 Systems Manager 參數,存放 CodePipeline 存放成品的 Amazon S3 儲存貯體。預設值為/blueprints/resources/artifacts-bucket-name。 -
CodeConnectionArn是 CodeConnections 連線至 GitHub 的 Amazon Resource Name (ARN)。
-
-
儲存並關閉 ServiceCatalog-Pipeline.yml 檔案。
-
輸入下列命令,將變更合併到程式碼儲存庫:
cd ServiceCatalog-CodeRepo git add ServiceCatalog-Pipeline.yml git commit -m "<description of change>" git push origin main -
在組態儲存庫 (
ServiceCatalog-ConfigRepo) 中,開啟 bp_config.yml 檔案。 -
視需要為您的組織更新產品組合區段中的值。例如,更新
portfolio_access_roles和share_to_ou屬性。如需詳細資訊,請參閱本指南中的組態檔案。 -
儲存並關閉 bp_config.yml 檔案。
-
輸入下列命令,將變更合併到程式碼儲存庫:
cd ServiceCatalog-ConfigRepo git add bp_config.yml git commit -m "<description of change>" git push origin main
部署 CloudFormation 堆疊
-
登入 Enterprise Blueprint Factory 管理帳戶。
-
切換到具有管理許可的 IAM 角色。
-
在畫面頂端的導覽列上,選擇目標 AWS 區域。
-
在堆疊頁面上,選擇右上角的建立堆疊,然後選擇使用新資源 (標準)。
-
針對 Prepare template (準備範本),選擇 Template is ready (範本已就緒)。
-
在指定範本下,選擇上傳範本檔案。
-
選擇選擇檔案,導覽至
ServiceCatalog-CodeRepo資料夾,然後選擇 ServiceCatalog-Pipeline.yml。 -
選擇下一步以繼續並驗證範本。
-
針對堆疊名稱,輸入堆疊的名稱。
-
在參數區段中,請勿變更預設值。
-
選擇下一步。
-
在設定堆疊選項頁面上,請勿變更預設值,然後選擇下一步。
-
在檢閱和建立頁面上,驗證範本和堆疊詳細資訊,然後選擇提交。
-
監控堆疊部署的進度。如需詳細資訊,請參閱 CloudFormation 文件。
-
等待狀態變更為
CREATE_COMPLETE。
驗證部署
-
在導覽窗格中,選擇產品。
-
確認 ServiceCatalog-Pipeline 可在產品清單中取得。
-
在名稱中,選擇組態管道。根據預設,管道名稱為
ServiceCatalog-Pipeline。 -
選擇 View history (檢視歷程記錄)。
-
檢視管道和階段執行的狀態。如需 狀態的詳細資訊,請參閱 CodePipeline 文件中的檢視執行狀態。
-
等到組態管道狀態為
Succeeded。 -
在導覽窗格中,選擇產品。
-
確認 BP-S3-Product 和 BP-SNS-Product 產品可用。這表示範例藍圖的產品發行管道已成功完成。
-
如果您想要刪除在設定企業藍圖工廠時部署的範例藍圖,請遵循刪除藍圖中的指示。
刪除企業藍圖工廠
如果您不是使用企業藍圖工廠,則可以將其刪除,以停止產生與其 AWS 資源相關聯的成本。
刪除 資源
-
輸入下列命令來刪除部署在 Enterprise Blueprint Factory 管理帳戶中的 IAM 角色:
aws iam detach-role-policy \ --policy-arn arn:aws:iam::aws:policy/AWSServiceCatalogEndUserFullAccess \ --role-name ServiceCatalogEndUserRole aws iam delete-role --role-name ServiceCatalogEndUserRole aws iam detach-role-policy \ --policy-arn arn:aws:iam::aws:policy/AmazonSNSFullAccess \ --role-name ServiceCataloglogLaunchConstraintRole aws iam delete-role --role-name ServiceCataloglogLaunchConstraintRole -
刪除企業藍圖工廠的 CloudFormation 堆疊。如需說明,請參閱從 CloudFormation 主控台刪除堆疊或從 刪除堆疊 AWS CLI。
-
刪除用於存放 CodePipeline 成品的 Amazon S3 儲存貯體。如需說明,請參閱 Amazon S3 文件中的刪除儲存貯體。
-
從參數存放區刪除下列 Systems Manager 參數:
-
/blueprints/resources/vpc_id -
/blueprints/resources/subnets -
/blueprints/resources/securitygroups -
/blueprints/resources/artifacts-bucket-name -
/blueprints/resources/BlueprintRepo -
/blueprints/resources/CodeRepo -
/blueprints/resources/ConfigRepo
如需說明,請參閱 Systems Manager 文件中的從參數存放區刪除參數。
-