CloudFormation "Requires Capabilities: [CAPABILITY_NAMED_IAM]": The Fix for the CLI, SAM, CodePipeline and Terraform, and Why Deleting RoleName Is Often Better
"Requires capabilities : [CAPABILITY_NAMED_IAM]" (an InsufficientCapabilitiesException) means your CloudFormation template creates IAM resources that you've given custom names, such as a role with RoleName, and CloudFormation wants you to acknowledge that before it goes ahead. The quick fix is one option: add --capabilities CAPABILITY_NAMED_IAM to create-stack, update-stack, create-change-set or aws cloudformation deploy, add it to sam deploy, set it in a CodePipeline action or a Terraform stack resource, or tick the acknowledgment box in the console. Here's what most answers leave out: the capability is a signature, not a permission, so it never fixes an AccessDenied. And the name that triggered it is often the real problem: IAM names are unique across your whole account, so a template with RoleName can't be deployed twice, in two Regions or for two environments, without a clash. Delete the name, and you only need CAPABILITY_IAM and the template deploys anywhere. This page shows the fix for every tool, how to find which resource needs which capability before you deploy, and when keeping the name is worth it.
Ethan, a developer, keeps the booking app for his friend Jake's phone repair shop in a CloudFormation template. Last week he gave the app's Lambda role a readable name, booking-app-role, so it would be easier to spot in the IAM console. The next deployment stopped at once with Requires capabilities : [CAPABILITY_NAMED_IAM]. He added the flag and it worked. Then Jake asked for a copy of the booking app in Europe for his cousin's shop, Ethan deployed the same template to another Region, and it failed again, this time because the role name was already taken. This page is both fixes, and why the second one mattered more.
New to CloudFormation or IAM? Our plain-English guide to stacks and our IAM policy guide cover the basics in a few minutes each.
Why CloudFormation asks for CAPABILITY_NAMED_IAM
IAM resources decide who can do what in your AWS account, so a template that creates them can quietly hand out a lot of power. Before CloudFormation creates or changes these resources, it wants a deliberate "yes, I know" from whoever runs the deployment. That "yes" is a capability. Without it, the request stops before anything is built:
An error occurred (InsufficientCapabilitiesException) when calling the CreateStack operation: Requires capabilities : [CAPABILITY_NAMED_IAM]
The same message appears from UpdateStack and CreateChangeSet, depending on which command you ran. These eight resource types trigger it:
| Resource type | What it creates |
|---|---|
AWS::IAM::Role | A role, such as a Lambda function's execution role |
AWS::IAM::Policy | An inline policy attached to roles, users or groups |
AWS::IAM::ManagedPolicy | A reusable managed policy |
AWS::IAM::User | An IAM user |
AWS::IAM::Group | An IAM group |
AWS::IAM::UserToGroupAddition | Users added to a group |
AWS::IAM::AccessKey | Access keys for a user |
AWS::IAM::InstanceProfile | An instance profile for EC2 |
Which capability you need depends on one thing: whether you named the resources yourself.
| Your template has | Capability you need |
|---|---|
| IAM resources, no custom names | CAPABILITY_IAM or CAPABILITY_NAMED_IAM |
IAM resources with a custom RoleName, UserName, GroupName or ManagedPolicyName | CAPABILITY_NAMED_IAM (required) |
Macros or transforms, such as AWS::Serverless or AWS::Include, when you create the stack directly instead of through a change set | CAPABILITY_AUTO_EXPAND |
CAPABILITY_NAMED_IAM covers unnamed IAM resources too, which is why many pipelines simply pass it every time. That's fine, as long as you know what it's acknowledging.
Jake: "So it's not asking for more access. It's asking you to sign the form."
Ethan: "Exactly. A signature that says, 'I know this template creates IAM things, and I looked.'"
The fix with the AWS CLI
Add the option to whichever command creates or updates the stack. For a new stack:
aws cloudformation create-stack \
--stack-name booking-app \
--template-body file://template.yaml \
--capabilities CAPABILITY_NAMED_IAM
For an existing stack:
aws cloudformation update-stack \
--stack-name booking-app \
--template-body file://template.yaml \
--capabilities CAPABILITY_NAMED_IAM
With aws cloudformation deploy, which most pipelines use:
aws cloudformation deploy \
--template-file template.yaml \
--stack-name booking-app \
--capabilities CAPABILITY_NAMED_IAM
And when you review changes first with a change set, the option goes on create-change-set, because that's where CloudFormation checks it:
aws cloudformation create-change-set \
--stack-name booking-app \
--change-set-name add-booking-role \
--change-set-type UPDATE \
--template-body file://template.yaml \
--capabilities CAPABILITY_NAMED_IAM
To pass more than one, list them with spaces: --capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND.
From Python (boto3)
import boto3
cfn = boto3.client("cloudformation")
with open("template.yaml") as f:
body = f.read()
cfn.create_stack(
StackName="booking-app",
TemplateBody=body,
Capabilities=["CAPABILITY_NAMED_IAM"],
)
cfn.get_waiter("stack_create_complete").wait(StackName="booking-app")
print("booking-app created")
In the boto3 error, the code is InsufficientCapabilitiesException. Our boto3 error handling guide shows how to catch it by name.
In the console
On the Configure stack options page of the Create stack or Update stack wizard, tick the acknowledgment: I acknowledge that this template may create IAM resources. That tick is the console's way of passing the capability.
SAM, CodePipeline, Terraform, CDK and GitHub Actions
Every tool that deploys a template has its own place for the same acknowledgment:
| Tool | Where the capability goes |
|---|---|
| AWS SAM CLI | sam deploy --capabilities CAPABILITY_NAMED_IAM, or capabilities in samconfig.toml |
| CodePipeline CloudFormation action | The Capabilities configuration property |
Terraform aws_cloudformation_stack | The capabilities argument |
| AWS CDK | Nothing: cdk deploy passes all three capabilities by itself |
| GitHub Actions with the AWS CLI | The --capabilities option on the CLI command |
AWS SAM
sam deploy --capabilities CAPABILITY_NAMED_IAM
To make it permanent, set it in samconfig.toml. Separate several values with spaces inside one string:
version = 0.1
[default.deploy.parameters]
stack_name = "booking-app"
capabilities = "CAPABILITY_IAM CAPABILITY_NAMED_IAM"
resolve_s3 = true
A SAM application that contains nested applications also needs CAPABILITY_AUTO_EXPAND. If sam deploy --guided wrote capabilities = "CAPABILITY_IAM" into your file and you later named a role, that line is why the error appears: change it to include CAPABILITY_NAMED_IAM.
CodePipeline
In a CloudFormation deploy action, set Capabilities in the action's configuration. Several values are separated by a comma with no space:
Configuration:
ActionMode: CREATE_UPDATE
StackName: booking-app
TemplatePath: BuildArtifact::template.yaml
Capabilities: CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND
RoleArn: arn:aws:iam::111122223333:role/cloudformation-deploy
Note the difference: a comma with no space in CodePipeline, spaces on the CLI and in samconfig.toml. Mixing them up is a common reason the error survives a "fix."
Terraform
If Terraform manages the CloudFormation stack, the capability goes in the stack resource:
resource "aws_cloudformation_stack" "booking_app" {
name = "booking-app"
template_body = file("template.yaml")
capabilities = ["CAPABILITY_NAMED_IAM"]
}
AWS CDK
cdk deploy always sends CAPABILITY_IAM, CAPABILITY_NAMED_IAM and CAPABILITY_AUTO_EXPAND with its requests, so CDK users don't see this error from cdk deploy. It appears when a template that CDK generated is deployed by something else, such as a CodePipeline CloudFormation action or aws cloudformation deploy on the cdk.out files. Add the capabilities there.
Jake: "Five tools, five places to write the same word."
Ethan: "And two different ways to separate it. That's the part that bites."
The better fix, often: stop naming your IAM resources
This is Ethan's second problem. IAM is not Regional: a role name must be unique across your whole account, and names don't care about upper or lower case. So a template with RoleName: booking-app-role works the first time and then can't be used again in the same account. Deploy it to a second Region, or as a second environment such as booking-app-test, and the role it tries to create already exists. The risk is bigger than a failed deployment: naming an IAM resource can cause an unrecoverable error if you reuse the template in several Regions, and stacks that end up sharing a named IAM resource can change each other's permissions when one of them is updated or deleted.
Names cause one more problem later. A resource with a custom name can't be replaced during an update, because CloudFormation creates the replacement before deleting the original, and the name is still taken. For a role, changing Path requires a replacement, so with a fixed RoleName that change fails until you also pick a new name.
You have three good options:
- Remove the name. Delete the
RoleNameline. CloudFormation then generates a unique name such asbooking-app-BookingRole-0USDR4QCV658, the template deploys in any Region and any number of times, andCAPABILITY_IAMis enough. Anything that needs the role can get it with!Ref BookingRole(the name) or!GetAtt BookingRole.Arn(the ARN), so nobody has to type the name. - Make the name unique per stack and Region. If people need a readable name in the IAM console, build it from the stack name and Region. You still need
CAPABILITY_NAMED_IAM, but copies no longer clash. - Keep a fixed name only for a one-of-a-kind role, such as a role another account trusts by name. Then deploy that template only once per account.
Option 2 looks like this:
AWSTemplateFormatVersion: '2010-09-09'
Resources:
BookingRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub '${AWS::StackName}-${AWS::Region}'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Outputs:
RoleArn:
Value: !GetAtt BookingRole.Arn
Before you remove a name from a stack that's already deployed, know what happens: RoleName can only be set when a role is created, so changing or removing it makes CloudFormation create a new role (with the new or generated name) and delete the old one in the same update. Resources in the same stack that use !Ref or !GetAtt follow the new role automatically. Anything outside the stack that refers to the old name or ARN, such as another account's trust policy, an S3 bucket policy or a script, has to be updated too, or it keeps pointing at a role that no longer exists.
A stack called booking-api in us-east-1 and eu-west-1 now gets booking-api-us-east-1 and booking-api-eu-west-1, side by side. Keep the result within IAM's 64-character limit for role names; long stack names plus long Region names can get close.
Jake: "So the pretty name is what broke Europe."
Ethan: "The pretty name was the same in both places. Let CloudFormation pick, or put the Region in it, and both shops can have their own."
Find out which capability a template needs before you deploy
Four steps, before the deployment rather than after the failure:
- Ask CloudFormation which capabilities the template needs with
validate-template, shown below. - Read the
Reason: it lists the resources that need them. - For each named IAM resource, decide: keep the name, make it Region-specific, or remove it.
- Add the capability that's left to the step that creates the stack or change set.
validate-template checks the template and returns the capabilities it requires, plus the list of resources that caused them:
aws cloudformation validate-template --template-body file://template.yaml \
--query '{Capabilities:Capabilities,Reason:CapabilitiesReason}'
An empty list means you don't need any. If it says CAPABILITY_NAMED_IAM, the Reason names the resources, so you can decide whether to keep their names before the deployment, not after a failure. Templates over 51,200 bytes need --template-url pointing at a copy in S3 instead of --template-body.
You can also search the template yourself. Any of these four property names means you need CAPABILITY_NAMED_IAM:
grep -nE 'RoleName|UserName|GroupName|ManagedPolicyName' template.yaml
When the error says CAPABILITY_AUTO_EXPAND instead
Requires capabilities : [CAPABILITY_AUTO_EXPAND] is a cousin of this error. It appears when your template uses a macro, which includes the AWS::Serverless transform behind every SAM template and the AWS::Include transform, and you create or update the stack directly instead of through a change set. Macros rewrite the template before deployment, and CloudFormation wants you to acknowledge that you're skipping the chance to review the result. Either add CAPABILITY_AUTO_EXPAND, or use a change set, which is what aws cloudformation deploy and sam deploy do. A template that has both macros and nested stacks must be created directly with this capability.
If the error lists two capabilities, such as [CAPABILITY_NAMED_IAM, CAPABILITY_AUTO_EXPAND], pass both.
Still getting an error after adding the capability?
The capability fixes exactly one error. If something still fails, read the new message carefully, because it's usually a different problem:
- You added it to the wrong command. In a pipeline with several steps, the capability has to be on the step that creates the stack or change set. Adding it to a later
execute-change-setstep does nothing; the check happened when the change set was created. - The separator is wrong. Commas with no space in CodePipeline, spaces on the CLI and in
samconfig.toml. - The new error is
AccessDenied. The capability doesn't grant anything. The identity running the deployment, or the CloudFormation service role passed with--role-arn, still needs IAM permissions such asiam:CreateRoleandiam:PutRolePolicyfor the resources in your template. - The new error says the role already exists. That's the naming clash from the section above. Remove or regionalize the name; if a leftover role from an old stack is in the way, our "already exists" guide shows how to import it instead of deleting it.
- The update fails because a custom-named resource needs replacing. Give the resource a new name in the same update, or remove the name.
- The capability is for a different stack. In a CI job that deploys several stacks, check the error's stack name against the command you fixed.
The IAM permissions CloudFormation needs to create a role
If the capability is in place and the deployment now fails with AccessDenied, the identity running it is missing IAM permissions. Here is what CloudFormation calls when it manages an AWS::IAM::Role: iam:CreateRole, iam:GetRole, iam:PutRolePolicy, iam:GetRolePolicy, iam:AttachRolePolicy, iam:TagRole and iam:UntagRole to create a role; iam:UpdateRole, iam:UpdateRoleDescription, iam:UpdateAssumeRolePolicy, iam:DetachRolePolicy, iam:DeleteRolePolicy and the permissions-boundary actions to update it; and iam:DeleteRole plus the list actions to delete it. Scoped to roles whose names start with the stack name, which covers generated names such as booking-app-BookingRole-0USDR4QCV658:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ManageBookingAppRoles",
"Effect": "Allow",
"Action": [
"iam:CreateRole",
"iam:GetRole",
"iam:UpdateRole",
"iam:UpdateRoleDescription",
"iam:UpdateAssumeRolePolicy",
"iam:DeleteRole",
"iam:PutRolePolicy",
"iam:GetRolePolicy",
"iam:DeleteRolePolicy",
"iam:AttachRolePolicy",
"iam:DetachRolePolicy",
"iam:ListRolePolicies",
"iam:ListAttachedRolePolicies",
"iam:PutRolePermissionsBoundary",
"iam:DeleteRolePermissionsBoundary",
"iam:TagRole",
"iam:UntagRole"
],
"Resource": "arn:aws:iam::111122223333:role/booking-app-*"
}
]
}
Replace the account ID and the name prefix with yours. If the stack also creates a Lambda function that uses the role, the deploying identity needs iam:PassRole on that role as well, because handing a role to a service is a separate permission. Scoping by name prefix is one more reason generated names are convenient: they always start with the stack name, so one pattern covers every role the stack will ever create.
Is it safe to always pass CAPABILITY_NAMED_IAM?
In a pipeline, passing it every time is common and reasonable: the review should happen when the template changes, not at deploy time. What matters is that someone reads the IAM parts of every template change before it's merged. Watch especially for "Action": "*" or "Resource": "*" in policies, new AWS::IAM::User or AWS::IAM::AccessKey resources, and trust policies that let other accounts assume a role. If you want a hard stop, keep production deployments on a separate role whose permissions only allow the IAM changes you expect, so an unexpected policy fails with AccessDenied even though the capability was given.
Still stuck? Troubleshooting by symptom
Requires capabilities : [CAPABILITY_NAMED_IAM] on create-stack or update-stack
Add --capabilities CAPABILITY_NAMED_IAM to the same command. Your template names a role, user, group or managed policy.
Requires capabilities : [CAPABILITY_IAM]
The template has IAM resources without custom names. Either CAPABILITY_IAM or CAPABILITY_NAMED_IAM fixes it.
The error appeared after a SAM deploy that worked before
Someone added a name to an IAM resource, and samconfig.toml still says capabilities = "CAPABILITY_IAM". Add CAPABILITY_NAMED_IAM to that line.
CodePipeline still fails after setting Capabilities
Check that values are separated by a comma with no space, and that the property is on the action that creates the stack or change set, not only on the one that executes it.
The same template fails in a second Region
The IAM name is already taken in your account. Remove the name or build it from ${AWS::StackName} and ${AWS::Region}.
AccessDenied after adding the capability
The capability isn't a permission. Give the deploying identity, or the CloudFormation service role, the IAM permissions your template's resources need.
cdk deploy never asked for it, but the pipeline does
CDK passes all three capabilities itself. Your pipeline deploys CDK's generated template with another tool; add the capabilities to that tool's step.
CAPABILITY_NAMED_IAM: frequently asked questions
What does "Requires capabilities : [CAPABILITY_NAMED_IAM]" mean?
Your CloudFormation template creates IAM resources with custom names, such as a role with RoleName, and CloudFormation needs your explicit acknowledgment before it creates or updates them. Add CAPABILITY_NAMED_IAM to the command, tool setting or console checkbox you deploy with.
How do I fix InsufficientCapabilitiesException?
Add the capability the error lists to the command that creates or updates the stack: --capabilities CAPABILITY_NAMED_IAM for named IAM resources, CAPABILITY_IAM for unnamed ones, CAPABILITY_AUTO_EXPAND for macros. In SAM, CodePipeline and Terraform, use their capabilities settings.
What is the difference between CAPABILITY_IAM and CAPABILITY_NAMED_IAM?
Both acknowledge that a template creates IAM resources. CAPABILITY_IAM is enough when those resources have no custom names; CAPABILITY_NAMED_IAM is required when you set RoleName, UserName, GroupName or ManagedPolicyName. CAPABILITY_NAMED_IAM also covers unnamed resources.
Does CAPABILITY_NAMED_IAM give CloudFormation permissions?
No. It's an acknowledgment, not a permission. The identity running the deployment, or the CloudFormation service role, still needs IAM permissions such as iam:CreateRole for the resources in your template, or the deployment fails with AccessDenied.
How do I add CAPABILITY_NAMED_IAM to sam deploy?
Run sam deploy --capabilities CAPABILITY_NAMED_IAM, or set capabilities = "CAPABILITY_IAM CAPABILITY_NAMED_IAM" under [default.deploy.parameters] in samconfig.toml. Separate several values with spaces.
How do I add CAPABILITY_NAMED_IAM in CodePipeline?
In the CloudFormation deploy action, set the Capabilities configuration property, for example CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND. Separate values with a comma and no space, and set it on the action that creates the stack or change set.
Does CDK need CAPABILITY_NAMED_IAM?
Not with cdk deploy, which always passes CAPABILITY_IAM, CAPABILITY_NAMED_IAM and CAPABILITY_AUTO_EXPAND. You need to add it only when another tool, such as a CodePipeline action, deploys the template CDK generated.
How do I add capabilities in the CloudFormation console?
On the Configure stack options page of the Create stack or Update stack wizard, tick "I acknowledge that this template may create IAM resources" before submitting.
Why does my CloudFormation template fail in a second Region?
IAM names are unique across your whole account, not per Region. A template with a fixed RoleName tries to create the same role again. Remove the name, or build it from the stack name and Region with !Sub.
Should I give IAM roles names in CloudFormation?
Usually not. Without a name, CloudFormation generates a unique one, the template can be deployed anywhere, and CAPABILITY_IAM is enough. Reference the role with !Ref or !GetAtt. Name a role only when something outside the stack must find it by name.
What is CAPABILITY_AUTO_EXPAND?
An acknowledgment for templates with macros, including the AWS::Serverless and AWS::Include transforms, when you create or update a stack directly instead of through a change set. It also applies to SAM applications with nested applications.
How can I tell which capabilities a template needs?
Run aws cloudformation validate-template --template-body file://template.yaml. Its Capabilities field lists what's required and CapabilitiesReason names the resources that need them.
Which IAM resources require capabilities?
AWS::IAM::Role, Policy, ManagedPolicy, User, Group, UserToGroupAddition, AccessKey and InstanceProfile. Any of them needs CAPABILITY_IAM or CAPABILITY_NAMED_IAM, and custom names on roles, users, groups and managed policies require CAPABILITY_NAMED_IAM.
How do I pass multiple capabilities with the AWS CLI?
Separate them with spaces after --capabilities, for example --capabilities CAPABILITY_NAMED_IAM CAPABILITY_AUTO_EXPAND. The same goes for aws cloudformation deploy and sam deploy.
What happens if I remove RoleName from a deployed stack?
CloudFormation replaces the role: it creates a new one with a generated name and deletes the old one in the same update. Resources in the stack that use !Ref or !GetAtt follow automatically; anything outside the stack that uses the old name or ARN must be updated.
What IAM permissions does CloudFormation need to create a role?
iam:CreateRole, iam:GetRole, iam:PutRolePolicy, iam:GetRolePolicy, iam:AttachRolePolicy, iam:TagRole and iam:UntagRole to create it, plus update and delete actions such as iam:UpdateAssumeRolePolicy and iam:DeleteRole, and iam:PassRole if a Lambda function in the stack uses the role.
Is it safe to always use CAPABILITY_NAMED_IAM in a pipeline?
It's common and fine, provided every template change that touches IAM is reviewed before merging. For a hard limit, give the deployment role only the IAM permissions you expect, so unexpected policies fail with AccessDenied.
For readers preparing for an AWS certification
We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.
Exams that test this topic: DevOps Engineer – Professional (DOP-C02) • CloudOps Engineer – Associate (SOA-C03).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. When does CloudFormation require CAPABILITY_NAMED_IAM?
When the template creates IAM resources with custom names.
2. When is CAPABILITY_IAM enough?
When IAM resources are created without explicit names.
3. Which capability do SAM templates and macros need?
CAPABILITY_AUTO_EXPAND.
4. Why does CloudFormation ask for these acknowledgements?
IAM changes can grant broad permissions, so you must confirm them explicitly.
5. How do you pass capabilities in the CLI?
--capabilities CAPABILITY_NAMED_IAM on create-stack, update-stack or deploy.
6. How do you limit what a stack can do with IAM?
Deploy with a CloudFormation service role that has only the permissions the stack needs.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
Ethan took the name off the booking role. The template now deploys with CAPABILITY_IAM in both Regions, and the European copy for Jake's cousin got its own role with a generated name nobody has to remember, because the Lambda function finds it with !GetAtt. He kept one named role: the one Jake's accountant's monitoring account trusts by name, deployed once in its own small template. Ethan wrote the line below in the repository's README.
📌 If you keep one line from this page
CAPABILITY_NAMED_IAM is a signature, not a permission; add it where the stack or change set is created, and before you do, ask whether that IAM name needs to exist at all.
Spaces on the CLI and in samconfig.toml, a comma with no space in CodePipeline; CDK passes all three by itself.
Revision note. Written October 13, 2026, for every role that got a nice name and then a second Region. "What's in a name?" asked Shakespeare; in IAM, sometimes a deployment that only works once.