本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 Git 同步將堆疊同步至 Git 儲存庫的先決條件
將 CloudFormation 堆疊同步至 Git 儲存庫之前,請確認符合下列要求。
Git 儲存庫
您必須在下列其中一個平台上託管 Git 儲存庫。
儲存庫可以是公有或私有。您需要透過 Connections 主控台
CloudFormation 範本
您的 Git 儲存庫必須包含 CloudFormation 範本檔案,該檔案會簽入您要使用 Git 同步連線的分支。此範本將由堆疊部署檔案參考。
Git 同步服務角色
Git 同步需要 IAM 角色。設定 Git 同步時,您可以選擇為堆疊建立 IAM 角色,也可以使用現有角色。
注意
自動產生的 IAM 角色僅會將許可套用至為其產生角色的堆疊。若要重複使用自動產生的 IAM 角色,您必須編輯新堆疊的角色。
Git 同步服務角色的必要許可
您為 Git 同步提供的 IAM 角色需要下列許可。
-
cloudformation:CreateChangeSet
-
cloudformation:DeleteChangeSet
-
cloudformation:DescribeChangeSet
-
cloudformation:DescribeStackEvents
-
cloudformation:DescribeStacks
-
cloudformation:ExecuteChangeSet
-
cloudformation:ListChangeSets
-
cloudformation:ValidateTemplate
-
events:PutRule
-
events:PutTargets
注意
上述必要許可會自動新增至 Git 同步產生的 IAM 角色。
下列 IAM 角色範例包含 Git 同步的先決條件許可。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "SyncToCloudFormation", "Effect": "Allow", "Action": [ "cloudformation:CreateChangeSet", "cloudformation:DeleteChangeSet", "cloudformation:DescribeChangeSet", "cloudformation:DescribeStackEvents", "cloudformation:DescribeStacks", "cloudformation:ExecuteChangeSet", "cloudformation:GetTemplate", "cloudformation:ListChangeSets", "cloudformation:ListStacks", "cloudformation:ValidateTemplate" ], "Resource": "*" }, { "Sid": "PolicyForManagedRules", "Effect": "Allow", "Action": [ "events:PutRule", "events:PutTargets" ], "Resource": "*", "Condition": { "StringEquals": { "events:ManagedBy": ["cloudformation.sync.codeconnections.amazonaws.com"] } } }, { "Sid": "PolicyForDescribingRule", "Effect": "Allow", "Action": "events:DescribeRule", "Resource": "*" } ] }
信任政策
建立角色以定義信任關係時,您必須提供下列信任政策。
主控台使用者的 IAM 許可
若要透過 CloudFormation 主控台成功設定 Git 同步,還必須透過 IAM 授予最終使用者許可。
需要下列codeconnections
許可才能建立和管理與Git儲存庫的連線。
-
codeconnections:CreateRepositoryLink
-
codeconnections:CreateSyncConfiguration
-
codeconnections:DeleteRepositoryLink
-
codeconnections:DeleteSyncConfiguration
-
codeconnections:GetRepositoryLink
-
codeconnections:GetSyncConfiguration
-
codeconnections:ListRepositoryLinks
-
codeconnections:ListSyncConfigurations
-
codeconnections:ListTagsForResource
-
codeconnections:TagResource
-
codeconnections:UntagResource
-
codeconnections:UpdateRepositoryLink
-
codeconnections:UpdateSyncBlocker
-
codeconnections:UpdateSyncConfiguration
-
codeconnections:UseConnection
主控台使用者也必須具備下列cloudformation
許可,才能在 Git 同步設定程序期間檢視和管理堆疊。
-
cloudformation:CreateChangeSet
-
cloudformation:DeleteChangeSet
-
cloudformation:DescribeChangeSet
-
cloudformation:DescribeStackEvents
-
cloudformation:DescribeStacks
-
cloudformation:ExecuteChangeSet
-
cloudformation:GetTemplate
-
cloudformation:ListChangeSets
-
cloudformation:ListStacks
-
cloudformation:ValidateTemplate
注意
雖然僅主控台的使用可能不需要變更集許可 (cloudformation:CreateChangeSet
、cloudformation:DeleteChangeSet
cloudformation:DescribeChangeSet
、、cloudformation:ExecuteChangeSet
),但建議您啟用完整的堆疊檢查和管理功能。
下列範例 IAM 政策包含透過主控台設定 Git 同步所需的使用者許可。
{ "Version": "2012-10-17", "Statement": [ { "Sid": "CodeConnectionsPermissions", "Effect": "Allow", "Action": [ "codeconnections:CreateRepositoryLink", "codeconnections:CreateSyncConfiguration", "codeconnections:DeleteRepositoryLink", "codeconnections:DeleteSyncConfiguration", "codeconnections:GetRepositoryLink", "codeconnections:GetSyncConfiguration", "codeconnections:ListRepositoryLinks", "codeconnections:ListSyncConfigurations", "codeconnections:ListTagsForResource", "codeconnections:TagResource", "codeconnections:UntagResource", "codeconnections:UpdateRepositoryLink", "codeconnections:UpdateSyncBlocker", "codeconnections:UpdateSyncConfiguration", "codeconnections:UseConnection", "codeconnections:CreateForcedTargetSync", "codeconnections:CreatePullRequestForResource" ], "Resource": "*" }, { "Sid": "CloudFormationConsolePermissions", "Effect": "Allow", "Action": [ "cloudformation:CreateChangeSet", "cloudformation:DeleteChangeSet", "cloudformation:DescribeChangeSet", "cloudformation:DescribeStackEvents", "cloudformation:DescribeStacks", "cloudformation:ExecuteChangeSet", "cloudformation:GetTemplate", "cloudformation:ListChangeSets", "cloudformation:ListStacks", "cloudformation:ValidateTemplate" ], "Resource": "*" } ] }
注意
建立包含 許可codeconnections:CreateForcedTargetSync
和 的 IAM 政策時codeconnections:CreatePullRequestForResource
,您可能會在 IAM 主控台中看到警告,指出這些動作不存在。您可以忽略此警告,且政策仍會成功建立。即使 IAM 主控台無法辨識,某些 Git 同步操作仍需要這些許可。