在使用CloudFormation创建堆栈时,我遇到了如下错误:
堆栈更新错误:需要以下能力:[CAPABILITY_IAM]
我找不到将 CAPABILITIES_IAM
添加到CloudFormation配置的模板。
解决 CAPABILITIES_IAM
错误的选项有哪些?
在使用CloudFormation创建堆栈时,我遇到了如下错误:
堆栈更新错误:需要以下能力:[CAPABILITY_IAM]
我找不到将 CAPABILITIES_IAM
添加到CloudFormation配置的模板。
解决 CAPABILITIES_IAM
错误的选项有哪些?
事实证明,在堆栈创建的最后一个屏幕上需要勾选一个框。如果您使用控制台,则在“创建堆栈”按钮上方有一个框,询问您是否要承认要允许Cloudformation修改IAM内容。当然,您也可以创建不需要确认的堆栈,这将导致堆栈失败并显示CAPABILITY_IAM
错误(或者如果需要其他功能,则可能会显示其他错误)。
在CodePipeline CloudFormation中,您可以像这样添加它以允许在部署操作中执行创建的change_set:
Configuration:
StackName: !Ref GitHubRepository
ActionMode: CHANGE_SET_REPLACE
Capabilities: CAPABILITY_NAMED_IAM
RoleArn: arn:aws:iam::818272543125:role/events-list-codepiplinerole
ChangeSetName: !Join ["",[!Ref GitHubRepository, "-changeset"]]
TemplatePath: MyAppBuild::sam_post.yaml
在AWS CLI中追加
--capabilities CAPABILITY_IAM
或者 (or)--capabilities CAPABILITY_NAMED_IAM
像这样输入您的指令:
aws cloudformation create-stack --stack-name message-store --template-body file://bucket_with_keys.yaml --parameters file://cfg_bucket_with_keys.json --capabilities CAPABILITY_NAMED_IAM
这不适用于cloudformation --validate-template,因为它实际上并未创建资源。
aws cloudformation create-stack
命令添加一个额外的参数,明确表示您需要提供这些功能。--capabilities CAPABILITY_IAM
,因此您的命令将如下所示:
aws cloudformation create-stack --stack-name $STACK_NAME --capabilities CAPABILITY_IAM
希望能对您有所帮助。validate-template
不能用?我的完整命令:aws cloudformation validate-template --template-body file://sqs-template.yml --capabilities CAPABILITY_IAM
- Michael M"CapabilitiesReason": "The following resource(s) require capabilities: [AWS::IAM::Role]"
,那就意味着你的模板是有效的,你需要在创建堆栈时指定返回能力。来源 - Matt Klein如果有人从谷歌(就像我一样)来到这里,并且正在使用 Terraform,请确保添加 capabilities 参数:
resource "aws_cloudformation_stack" "cloudformation_stack" {
# ...
capabilities = [ "CAPABILITY_IAM" ]
}
https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html
如果有人在使用 SAM 进行部署时遇到相同的问题,只需要添加 --capabilities 标志即可:
sam deploy --guided --capabilities CAPABILITY_NAMED_IAM
sam deploy --capabilities CAPABILITY_IAM
或者
sam deploy --capabilities CAPABILITY_NAMED_IAM
sam deploy --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM
capabilities = "CAPABILITY_IAM CAPABILITY_NAMED_IAM"
--capabilities CAPABILITY_NAMED_IAM
。 - Chau Giang