在使 CloudFormation 堆栈与 Git 存储库同步之前,确认满足以下要求。
Git 存储库
您必须将 Git 存储库托管在以下平台之一上:
存储库可以是公有的,也可以是私有的。您需要通过 Connections 控制台
CloudFormation 模板
您的 Git 存储库必须包含 CloudFormation 模板文件,且该文件已签入您打算连接到 Git 同步的分支。堆栈部署文件将引用此模板。
IAM 角色
Git 同步需要 IAM 角色。您可以选择在配置 Git 同步时为堆栈创建 IAM 角色,也可以使用现有角色。
注意
自动生成的 IAM 角色仅将权限应用于为其生成角色的堆栈。要重复使用自动生成的 IAM 角色,必须编辑新堆栈的角色。
所需的权限
为 Git 同步提供的 IAM 角色需要以下权限:
注意
上述所需权限会自动添加到 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": "*"
}
]
}
信任策略
Git 同步需要以下信任策略才能连接到 Git 存储库:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CfnGitSyncTrustPolicy",
"Effect": "Allow",
"Principal": {
"Service": "cloudformation.sync.codeconnections.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}