IAM "Cannot Exceed Quota for PoliciesPerRole": The Default Is Now 20, How to Raise It to 25 in Minutes, and What to Do When 25 Is Not Enough
"Cannot exceed quota for PoliciesPerRole" means the IAM role already has as many managed policies attached as your account allows, so IAM refuses to attach one more (it returns LimitExceeded, HTTP 409). The number at the end of the message is your current limit. It has nothing to do with how big the policies are; that is a different error. The surprise is the number itself: most guides still say the limit is 10, but the default today is 20 managed policies per role, and you can raise it to 25 in Service Quotas, where requests up to that maximum are approved automatically within a few minutes. Past 25 there is no increase at all, so the real fix is to combine policies into fewer customer managed ones, move some permissions into an inline policy (inline policies do not count toward this limit), or split the role. This page covers checking your real limit, raising it, merging policies safely, the related errors for users, groups and trust policies (PoliciesPerUser, PoliciesPerGroup, ACLSizePerRole), IAM Identity Center permission sets, and how the error shows up in Terraform, CloudFormation and the CDK.
Ethan's deploy role for Jake's booking app had grown one policy at a time for two years: a read-only policy here, a Lambda policy there, an extra one every time a deploy failed with access denied. When the shop added an AI feature, the next deploy stopped with the error above. Jake read it over his shoulder. "So we hit a size limit?" "We hit a count limit," Ethan said. "Twenty policies on one role. Nobody ever took one off." This page is how Ethan got the deploy running again in ten minutes, and how he made sure he would not need the quota increase a second time.
New to IAM? A role is an identity that services, people and pipelines take on to get permissions. Permissions come from policies, JSON documents that list what is allowed (our policy explainer walks through one line by line). A managed policy is a standalone policy you attach to many identities (AWS managed ones such as ReadOnlyAccess, or customer managed ones you write). An inline policy lives inside one role only. This error is about the first kind.
What "Cannot exceed quota for PoliciesPerRole" means
The full message from the AWS CLI looks like this, with your limit at the end:
An error occurred (LimitExceeded) when calling the AttachRolePolicy operation: Cannot exceed quota for PoliciesPerRole: 20
IAM is telling you that the role named in the call already has 20 managed policies attached (or whatever your number is) and one more would go over. It does not matter whether the new policy is tiny or which policies are already there; AWS managed and customer managed policies both count, one each. IAM uses the same LimitExceeded error for several different quotas, so read the word after "quota for" before you fix anything:
| The message says | What is full | Default / maximum | Fix |
|---|---|---|---|
PoliciesPerRole | Managed policies attached to one role | 20 / 25 | Raise to 25, merge, go inline, split |
PoliciesPerUser | Managed policies attached to one user | 10 / 20 | Raise, or move the user into a group |
PoliciesPerGroup | Managed policies attached to one group | 10 / 10 (no increase) | Merge, or use a second group |
ACLSizePerRole | The role's trust policy length | 2,048 / 8,192 characters | Raise, or shorten the trust policy |
| Policy size messages | One managed policy over 6,144 characters, or a role's inline policies over 10,240 in total | Fixed, no increase | Split or shorten the policy (size guide) |
| Five versions | A managed policy already has 5 saved versions | 5, fixed | Delete an old version first |
The groups row is the one that surprises people: a group can never hold more than 10 managed policies, and that quota cannot be raised. If you organize permissions through groups, merging is the only way past it.
Check your real limit and how many policies the role has
Start with two numbers: your account's limit and the role's current count. The account summary shows every IAM quota that applies to you:
aws iam get-account-summary --query "SummaryMap.{PerRole:AttachedPoliciesPerRoleQuota,PerUser:AttachedPoliciesPerUserQuota,PerGroup:AttachedPoliciesPerGroupQuota,TrustPolicy:AssumeRolePolicySizeQuota,RoleInline:RolePolicySizeQuota,ManagedSize:PolicySizeQuota,Versions:VersionsPerPolicyQuota}"
aws iam list-attached-role-policies --role-name booking-deploy \
--query "length(AttachedPolicies)"
If the first number equals the second, that role is full. To find every role that is close, before the next deploy fails, this loop prints roles with 15 or more managed policies, fullest first:
for r in $(aws iam list-roles --query "Roles[].RoleName" --output text); do
n=$(aws iam list-attached-role-policies --role-name "$r" --query "length(AttachedPolicies)" --output text)
[ "$n" -ge 15 ] && echo "$n $r"
done | sort -rn
Then list what is actually on the full role, because the fastest fix is often removing a policy nobody needs any more:
aws iam list-attached-role-policies --role-name booking-deploy \
--query "AttachedPolicies[].PolicyArn" --output text | tr '\t' '\n'
Look for duplicates in disguise: AmazonS3FullAccess next to AmazonS3ReadOnlyAccess (the read-only one adds nothing), AdministratorAccess next to anything (everything else adds nothing), or three customer managed policies that each grant one action on the same bucket. When Ethan ran this on the deploy role, two of the twenty were AWS managed read-only policies already covered by full-access ones. Detaching those two got the deploy through before any quota request.
If you are not sure a policy is unused, IAM's last-accessed information shows when the role last used each service. In the console, open the role and choose the Last Accessed tab; a service the role has not touched in 90 days is a good candidate to remove.
The 10-minute fix when a deploy is blocked right now
When the error is blocking a release, this order gets you moving fastest with the least risk, and leaves the proper cleanup for later:
- Read the number at the end of the message and confirm it with
aws iam get-account-summary. Anything below 25 means a quota request can add room. - List the role's policies and detach anything clearly redundant (a read-only policy beside the full-access one for the same service, a policy for a feature you removed). One or two detached usually unblocks the deploy at once.
- If nothing is safely removable, request the increase to 25 in Service Quotas, US East (N. Virginia). It is approved automatically, normally within minutes.
- Retry the deploy. For CloudFormation stacks that rolled back on first creation, delete the stack first.
- Write down which role was full and schedule the merge or split from the sections below, so the extra room is not used up by the same habit.
Ethan did steps 1, 2 and 4 during the failed deploy, then step 3 anyway as a safety margin. "Detaching two policies fixed it," he told Jake. "The quota increase is so the next person does not panic."
What counts toward PoliciesPerRole, and what does not
Only managed policies attached to the role count, the ones list-attached-role-policies returns. Several other kinds of policy shape what a role can do without using a slot:
- Inline policies on the role: not counted (they share the 10,240-character inline budget instead).
- The permissions boundary: set with its own API call (
put-role-permissions-boundary) and shown separately on the role; it limits the role's maximum permissions and is not one of its attached policies. - The trust policy: part of the role, with its own length limit (
ACLSizePerRole), not a managed attachment. - Service control policies and resource control policies: attached in AWS Organizations to accounts and organizational units, never to the role.
- Resource-based policies (bucket policies, KMS key policies, queue policies): attached to the resource, so granting the role access from the resource side uses no role slot at all.
- Session policies passed when the role is assumed: temporary, never stored on the role.
The resource-based route is underused. If a role needs access to one bucket in the same account, a statement in the bucket policy naming the role works without touching the role. Across accounts, both sides must allow it (the role's own policy and the resource policy), so this trick saves slots mainly within one account.
Fewer, broader AWS managed policies (and when that is a bad idea)
Sometimes a role has a pile of narrow AWS managed policies that one AWS job function policy already covers. AWS maintains a set of job function policies designed for exactly these broad roles:
| Job function policy | Meant for | Watch out |
|---|---|---|
ViewOnlyAccess | Listing resources and basic metadata across services | Cannot read content, which is often what dashboards need |
ReadOnlyAccess | Reading every resource in the account | Includes reading data in S3 buckets and DynamoDB tables |
SecurityAudit | Compliance checks, logs and security configuration | Read-only; good for audit tools |
SystemAdministrator, DatabaseAdministrator, NetworkAdministrator | People who run operations, databases or networks | Broad within their area; meant for people, not pipelines |
PowerUserAccess | Developers building applications | Everything except IAM, Organizations and account management; very broad |
AdministratorAccess | Full administrators | Makes every other policy on the role pointless |
Swapping six read-only service policies for one ReadOnlyAccess on a monitoring role is a fair trade. Swapping a deploy role's twenty specific policies for PowerUserAccess just to get under the limit trades an error message for a much bigger blast radius if the pipeline's credentials leak. For roles used by automation, merging into a few customer managed policies is the safer way to save slots.
The IAM quotas that cause LimitExceeded, in one table
| Quota | Default | Maximum (auto-approved) |
|---|---|---|
| Managed policies per role | 20 | 25 |
| Managed policies per user | 10 | 20 |
| Managed policies per group | 10 | 10 |
| Role trust policy length | 2,048 characters | 8,192 characters |
| Customer managed policies per account | 1,500 | 10,000 |
| Roles per account | 1,000 | 10,000 |
| Groups per account | 300 | 500 |
| Instance profiles per account | 1,000 | 10,000 |
| OpenID Connect providers per account | 100 | 700 |
| Managed policy size | 6,144 characters | Cannot be raised |
| Inline policies per role, total size | 10,240 characters | Cannot be raised |
| Inline policies per user / per group, total size | 2,048 / 5,120 characters | Cannot be raised |
| Versions per managed policy | 5 | Cannot be raised |
IAM does not count whitespace toward the size limits, so the same policy pretty-printed or minified counts the same. Every "maximum" in the middle column is approved automatically when you request it, usually within a few minutes; nothing needs a support case.
Raise "Managed policies per role" to 25 in Service Quotas
IAM is a global service, so its quotas live in one place: Service Quotas in US East (N. Virginia). Requesting it from another Region is the most common reason people cannot find the quota at all.
- Sign in and open the Service Quotas console.
- In the Region selector, choose US East (N. Virginia).
- Choose AWS services, search for IAM, and choose AWS Identity and Access Management (IAM).
- Find Managed policies per role (search the list for "managed policies"), choose it, then Request increase at account level.
- Enter 25 and submit. The request history shows it approved, usually within minutes; then retry your attach or deploy.
From the CLI, look up the quota code first, then request the new value:
aws service-quotas list-service-quotas --service-code iam --region us-east-1 \
--query "Quotas[?contains(QuotaName, 'policies')].[QuotaName,QuotaCode,Value]" --output table
aws service-quotas request-service-quota-increase --service-code iam \
--quota-code QUOTA_CODE_FROM_ABOVE --desired-value 25 --region us-east-1
aws service-quotas list-requested-service-quota-change-history \
--service-code iam --region us-east-1 --query "RequestedQuotas[].[QuotaName,DesiredValue,Status]"
The quota is per account. In an AWS Organization, each account that needs it must request it (or you can add it to a Service Quotas request template so new accounts get it at creation). And 25 is the ceiling. If the role would need 26, the increase only buys time; the next sections are the lasting fix.
"So we just ask for 25 and we are done?" Jake asked. "We ask for 25 and we stop adding a policy every time something fails," Ethan said. "Otherwise we are back here in a year with nowhere to go."
When 25 is not enough: merge policies into fewer customer managed ones
Five small customer managed policies of one or two statements each can almost always become one. The limit that matters then is size: a managed policy can be up to 6,144 characters, whitespace not counted. Merge like this:
- List the customer managed policies on the role (those whose ARN contains your account ID rather than
aws), and pick the small ones that belong together, for example everything about the booking bucket. - Download each one's current version and merge the statements with
jq, dropping theSidfields so no two statements share one:for arn in arn:aws:iam::111122223333:policy/bucket-read arn:aws:iam::111122223333:policy/bucket-write; do v=$(aws iam get-policy --policy-arn "$arn" --query Policy.DefaultVersionId --output text) aws iam get-policy-version --policy-arn "$arn" --version-id "$v" --query PolicyVersion.Document done | jq -s '{Version: "2012-10-17", Statement: ([.[].Statement] | flatten | map(del(.Sid)))}' > merged.json jq -c . merged.json | wc -c # must stay at or under 6144 - Check the merged document before you trust it:
aws accessanalyzer validate-policy --policy-type IDENTITY_POLICY --policy-document file://merged.jsonreports errors and security warnings. - Create it, attach it, and only then detach the old ones:
aws iam create-policy --policy-name booking-bucket --policy-document file://merged.json, thenattach-role-policywith the new ARN, run your deploy or tests, anddetach-role-policyfor each old one. - Delete the old policies when nothing else uses them; IAM refuses while they are still attached anywhere (our DeleteConflict guide shows how to find where).
Two cautions. Merging keeps every Deny statement, which is what you want, but read the result once: a deny that applied to one narrow resource still applies to the same resource after the merge, nothing more. And think twice before copying an AWS managed policy into your own. AWS updates its managed policies when services add actions; your copy will not change, so features that need new permissions start failing later with access denied, months after you have forgotten why. Merge your own policies first; keep AWS managed ones attached as they are.
Use an inline policy for the role's own permissions
Inline policies do not count toward PoliciesPerRole at all. A role can have as many inline policies as you like, as long as all of them together stay within 10,240 characters. That makes inline a good home for permissions that belong to this one role and would never be reused elsewhere: access to one specific bucket, one queue, one table.
aws iam put-role-policy --role-name booking-deploy \
--policy-name booking-app-resources \
--policy-document file://booking-app-resources.json
aws iam list-role-policies --role-name booking-deploy
| Managed policy | Inline policy | |
|---|---|---|
| Counts toward PoliciesPerRole | Yes, one each | No |
| Size limit | 6,144 characters per policy | 10,240 characters for all of a role's inline policies together |
| Reusable on other roles | Yes | No, it belongs to one role |
| Versions and rollback | Up to 5 versions, set any as default | None; you overwrite it |
| Deleted with the role | No | Yes |
| Best for | Permission sets shared by many roles | Resource access only this role needs |
In Terraform, the inline version is the aws_iam_role_policy resource. Moving a role-specific managed policy inline looks like this; the attachment and the standalone policy go away, and the role keeps the same permissions:
resource "aws_iam_role_policy" "booking_resources" {
name = "booking-app-resources"
role = aws_iam_role.booking_deploy.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = ["s3:GetObject", "s3:PutObject"]
Resource = "arn:aws:s3:::booking-uploads/*"
}]
})
}
Apply the new inline policy first and remove the old aws_iam_role_policy_attachment in the same change, so there is no moment when the role has neither. Keep an eye on the 10,240-character total: three or four large inline policies on one role can reach it, and then you are back to splitting.
Infrastructure tools already lean on this. The CDK's grant methods (bucket.grantRead(role) and friends) write their statements into one policy resource per role, the role's default policy, rather than attaching a new managed policy for every grant, so a CDK app with dozens of grants uses no managed policy slot for them at all. If your CDK role hits the limit, look at the managedPolicies you added by hand, not at the grants.
Split the role when it does too many jobs
A role with 25 policies is usually a sign that one identity is doing several jobs. Jake's deploy role was deploying the website, running database migrations and publishing the AI feature, each with its own set of permissions. Splitting it gives each job only what it needs, which is safer as well as shorter:
- One role per pipeline stage or per application. The deploy job for the website assumes the website role; the migration job assumes the database role. In GitHub Actions, that is a different
role-to-assumeper job (our OIDC guide covers the trust policy for each). - Role chaining where one process needs two sets. The process assumes its main role, then assumes a second role for the extra permissions. A chained session is limited to one hour, so this suits short tasks rather than long-running services.
- Service roles stay separate. A Lambda function, an ECS task and an EC2 instance should each have their own execution role instead of sharing a deploy role.
Splitting takes the longest of all the fixes, but it is the only one that also shrinks what a leaked credential could do. For the deploy role, Ethan split the AI feature into its own role in an afternoon, which took the original role from 20 policies down to 13.
The roles that usually fill up, and the better home for their policies
Some roles hit the limit far more often than others, and each has a cleaner fix than a quota increase:
- EKS node roles. They start with
AmazonEKSWorkerNodePolicy,AmazonEKS_CNI_PolicyandAmazonEC2ContainerRegistryReadOnly, then collectAmazonSSMManagedInstanceCore,CloudWatchAgentServerPolicy,AmazonEBSCSIDriverPolicy,AmazonEFSCSIDriverPolicyand one policy per add-on or application that runs on the nodes. Everything an add-on or pod needs belongs on its own role through IAM roles for service accounts or EKS Pod Identity instead; that also stops every pod on the node from inheriting it. - CI/CD deploy roles. They grow by one policy per failed deploy, as Ethan's did. Split them per application or per stage.
- Machine learning execution roles. A SageMaker or notebook role ends up with a policy per data source and per service the experiments touch. Group data access into one customer managed policy per project.
- "Admin but not quite" human roles. A role given fifteen full-access service policies to avoid
AdministratorAccessis often better served byPowerUserAccessplus a few narrow IAM permissions, or by IAM Identity Center permission sets per job.
PoliciesPerUser: move the permissions into groups
Users hit their own version of the error, Cannot exceed quota for PoliciesPerUser, at 10 managed policies by default (20 after an increase). The tidy fix is groups: permissions shared by several people go on a group, and each user simply joins it.
- List the user's policies:
aws iam list-attached-user-policies --user-name sam. - Create a group for the shared job, for example
aws iam create-group --group-name booking-developers, and attach the shared policies to it withattach-group-policy(remember: 10 per group, no increase). - Add the user:
aws iam add-user-to-group --user-name sam --group-name booking-developers. - Test the user's access, then detach the same policies from the user with
detach-user-policy.
Longer term, people are better served by IAM Identity Center than by IAM users with long-lived keys; permission sets then carry the policies, and the per-user limit stops mattering.
Raising the quota in every account of an AWS Organization
The quota is per account, so an organization with fifty accounts needs fifty requests, unless you use a Service Quotas request template. From the management account, add the IAM quota to the template once, and every new account created in the organization gets the request automatically:
aws service-quotas associate-service-quota-template --region us-east-1
aws service-quotas put-service-quota-increase-request-into-template \
--service-code iam --quota-code QUOTA_CODE --aws-region us-east-1 --desired-value 25 --region us-east-1
The template applies to accounts created after it is set up. For existing accounts, run the request-service-quota-increase command in each one (for example in a loop that assumes a role in every member account). Because these increases are approved automatically up to 25, the whole organization can be done in an afternoon.
ACLSizePerRole: when the trust policy is too long
A related message, Cannot exceed quota for ACLSizePerRole: 2048, comes from the role's trust policy (the "who may assume this role" document), not its permissions. The default limit is 2,048 characters, and it fills up fast when you list many accounts, many GitHub repositories or many single sign-on providers one by one. You can raise "Role trust policy length" to 8,192 characters in Service Quotas, auto-approved like the others. Before you do, three rewrites usually make it short again:
- Many accounts in your organization: replace the list of account principals with one condition,
"aws:PrincipalOrgID": "o-abc123example", which allows any principal from your AWS Organization (combine it with a narrow principal or role name pattern so it does not mean "anyone in the company"). - Many GitHub repositories or branches: one
StringLikecondition ontoken.actions.githubusercontent.com:subwith a pattern such asrepo:jakes-shop/*:ref:refs/heads/mainreplaces a long list of exact subjects. - Repeated statements: several statements with the same action and principal type can become one statement with a list of values.
Here is what that looks like for a GitHub Actions role trusted by many repositories. Before, one condition value per repository and branch:
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": [
"repo:jakes-shop/booking-api:ref:refs/heads/main",
"repo:jakes-shop/booking-web:ref:refs/heads/main",
"repo:jakes-shop/booking-admin:ref:refs/heads/main"
]
}
}
After, one pattern that covers every repository in the organization on its main branch, which stays the same length however many repositories you add:
"Condition": {
"StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" },
"StringLike": { "token.actions.githubusercontent.com:sub": "repo:jakes-shop/*:ref:refs/heads/main" }
}
The pattern is broader by design, so make sure every repository in that GitHub organization should be able to deploy with this role. If only some should, give the others a separate role rather than a longer list.
Whitespace does not count, so minifying the JSON changes nothing; the fix is fewer or shorter values. If the trust policy has many principals because many teams share one role, that is the "split the role" case again.
IAM Identity Center permission sets and PoliciesPerRole
With IAM Identity Center, each permission set becomes an IAM role in every account where it is assigned, so it is subject to the same per-role limit in each of those accounts. A permission set can hold up to 25 AWS managed and customer managed policies combined, plus one inline policy (up to 32,768 bytes, of which at most 10,240 non-whitespace characters). Provisioning fails in any account whose own "Managed policies per role" quota is lower than the number of policies in the permission set.
- Count the managed policies in the permission set (Identity Center console, Permission sets, open the set and look at its AWS managed and customer managed policies).
- If the count is above your accounts' per-role quota, request the IAM quota increase in each account where the permission set is provisioned, in US East (N. Virginia).
- Re-provision the permission set to those accounts; the permission set's list of AWS accounts shows the provisioning status of each.
- Better still, move account-specific resource permissions into the permission set's inline policy, and keep the managed list short.
Customer managed policies in a permission set are referenced by name and must exist, with that same name and path, in every account the set is provisioned to. A missing one fails provisioning with a different error, so check that first if the count looks fine.
How the error shows up in Terraform, CloudFormation and the CDK
Infrastructure code hits the limit at the moment it tries the 21st attachment (or the 26th after an increase), and each tool reports it its own way:
- Terraform: an
aws_iam_role_policy_attachment(or a role's list of managed policy ARNs) fails during apply with anAttachRolePolicyerror showingStatusCode: 409andLimitExceeded: Cannot exceed quota for PoliciesPerRole: 20. The attachments created earlier in the same apply stay in place, so after you fix the cause, a second apply completes the rest. - CloudFormation: the
AWS::IAM::RoleorAWS::IAM::ManagedPolicyresource fails with the same message followed by the service name and status code 409, and the stack rolls back. A new stack that fails on first creation ends inROLLBACK_COMPLETEand must be deleted before you try again. - CDK: the failure appears in the CloudFormation events of the deployment; the role's
managedPolicieslist (and everyaddManagedPolicycall) is what counts. Grants do not.
You can catch the problem in a Terraform plan before apply. This counts, per role, the policy attachments the plan will leave in place (new and existing ones), and prints any role at 20 or more:
terraform plan -out tf.plan >/dev/null
terraform show -json tf.plan | jq -r '
[.resource_changes[]
| select(.type == "aws_iam_role_policy_attachment")
| select(.change.actions != ["delete"])
| .change.after.role // .change.before.role]
| group_by(.) | map({role: first, n: length}) | .[] | select(.n >= 20) | "\(.n) \(.role)"'
It only sees attachments managed in that Terraform configuration; policies attached by hand or by another stack still count at apply time, so treat it as an early warning rather than a guarantee. When a policy really belongs to one role, Terraform's aws_iam_role_policy resource creates it inline, which keeps it out of the managed count entirely.
CloudFormation and CDK users can run the same kind of check on the template. After cdk synth, the templates are JSON files in cdk.out; for plain CloudFormation, convert YAML to JSON first. This lists every role with the number of managed policy ARNs it declares, largest first:
jq -r '.Resources | to_entries[]
| select(.value.Type == "AWS::IAM::Role")
| "\(.value.Properties.ManagedPolicyArns // [] | length) \(.key)"' cdk.out/BookingStack.template.json | sort -rn
An AWS::IAM::ManagedPolicy resource can also attach itself to roles through its own Roles property, and those attachments count too, so a role that looks light in this list can still be full. Add policies attached outside the template (by hand, or by another stack) and compare the total with your limit.
Two habits keep infrastructure code from hitting it again. Keep managed policies for genuinely shared permission sets and put resource access in a policy resource that belongs to the role (an inline policy, or the CDK's default policy). And add a check to your pipeline that counts the managed policies per role in the plan or template and fails above, say, 15, so the warning arrives long before the limit.
The other limit people hit while fixing this: five policy versions
Merging and editing policies means saving new versions, and a managed policy keeps at most five. On the sixth save, IAM refuses with a LimitExceeded error about versions. Delete the oldest non-default version, then save again:
aws iam list-policy-versions --policy-arn arn:aws:iam::111122223333:policy/booking-bucket \
--query "Versions[?IsDefaultVersion==\`false\`].[VersionId,CreateDate]" --output text | sort -k2 | head -1
aws iam delete-policy-version --policy-arn arn:aws:iam::111122223333:policy/booking-bucket --version-id v1
aws iam create-policy-version --policy-arn arn:aws:iam::111122223333:policy/booking-bucket \
--policy-document file://merged.json --set-as-default
The default version cannot be deleted; make another version the default first if you need to remove it. Terraform and CloudFormation handle this for you on updates, which is why the error shows up mostly in hand-run scripts.
Find full roles and handle the error in Python (boto3)
The shell loop above is fine for one account. For a scheduled check, or to give a clearer message when your own tooling attaches policies, a short boto3 script does both. This one reads the account's limit, reports roles at 75 percent or more, and shows how to catch the error when attaching:
import boto3
from botocore.exceptions import ClientError
iam = boto3.client("iam")
limit = iam.get_account_summary()["SummaryMap"]["AttachedPoliciesPerRoleQuota"]
full = []
for page in iam.get_paginator("list_roles").paginate():
for role in page["Roles"]:
name = role["RoleName"]
count = sum(len(p["AttachedPolicies"]) for p in
iam.get_paginator("list_attached_role_policies").paginate(RoleName=name))
if count >= limit * 0.75:
full.append((count, name))
for count, name in sorted(full, reverse=True):
print(f"{count}/{limit} {name}")
def attach(role_name, policy_arn):
try:
iam.attach_role_policy(RoleName=role_name, PolicyArn=policy_arn)
except ClientError as e:
if e.response["Error"]["Code"] == "LimitExceeded" and "PoliciesPerRole" in e.response["Error"]["Message"]:
raise SystemExit(f"{role_name} already has {limit} managed policies; merge or detach before adding {policy_arn}")
raise
The script needs iam:GetAccountSummary, iam:ListRoles, iam:ListAttachedRolePolicies and, for the attach function, iam:AttachRolePolicy. Service-linked roles appear in the list too; you cannot attach or detach their policies, because the owning service manages them, so leave them out of any cleanup.
For users, the same idea works with list_users and list_attached_user_policies. Users are usually better fixed by moving their permissions into groups; a user can belong to several groups, each with its own 10 policies (your account's group-membership limit is GroupsPerUserQuota in the account summary).
Keep roles well under the limit
The roles that hit this limit were not designed with 20 policies; they collected them. A few habits stop that:
- Fix access denied by reading the error, not by attaching a policy. The denied action is in the message; add that action to an existing policy instead of attaching a new full-access one.
- Review the fullest roles once a quarter with the loop above and the Last Accessed tab; remove what is unused.
- Prefer one well-named customer managed policy per purpose ("booking-bucket", "booking-queue") over many tiny ones.
- Raise the quota to 25 early in accounts with heavy roles, so the limit is a warning sign rather than a midnight outage. It is free and takes minutes.
Ethan added the counting loop to the shop's monthly checklist. "It takes a minute," he told Jake, "and it is the difference between an annoying error and an outage on a Friday."
PoliciesPerRole still failing? Troubleshooting by symptom
I raised the quota but the error still says 20
Check that the request was made in US East (N. Virginia) and shows as approved, and that it was in the same account as the role. Then retry; the new value applies within minutes of approval.
I cannot find "Managed policies per role" in Service Quotas
Your console is set to another Region. Switch to US East (N. Virginia), then open the IAM service in Service Quotas.
The error says PoliciesPerGroup
Groups are limited to 10 managed policies with no increase. Merge the group's policies, or put the users in a second group for the extra permissions.
The error says ACLSizePerRole
The trust policy is over its length limit. Shorten it with aws:PrincipalOrgID or a StringLike pattern, or raise Role trust policy length to 8,192.
Deleting an old policy fails with DeleteConflict
It is still attached to another role, user or group, or it has non-default versions. Detach it everywhere and delete its old versions first.
Identity Center provisioning fails in some accounts only
Those accounts have a lower per-role quota than the permission set's policy count, or are missing a customer managed policy by that name. Raise the quota or create the policy in each failing account, then re-provision.
Terraform apply fails halfway with LimitExceeded
The attachments before the failure were created. Remove or merge policies so the total fits, then apply again; Terraform picks up where it stopped.
CloudFormation stack is stuck in ROLLBACK_COMPLETE after the error
A stack that failed on creation cannot be updated. Delete it, fix the policy count, and create it again.
Access denied right after detaching a "redundant" policy
The policy you removed granted something the others did not, often a condition-free action or a second resource. Re-attach it, compare the two documents statement by statement, and copy only the missing statement into a policy you keep.
The full role is a service-linked role
You cannot attach or detach policies on a service-linked role; the owning service manages them. The error is coming from a different role, so check the role name in the failing call.
The merged policy is rejected as malformed
Duplicate Sid values or a statement shape jq did not expect. Remove the Sid fields, validate with IAM Access Analyzer, and check our MalformedPolicyDocument guide.
IAM PoliciesPerRole: frequently asked questions
What does "Cannot exceed quota for PoliciesPerRole" mean?
The role already has as many managed policies attached as your account allows, and IAM will not attach another. The number at the end of the message is your current limit.
How many managed policies can be attached to an IAM role?
20 by default, and up to 25 after a quota increase in Service Quotas, which is approved automatically. There is no way to go beyond 25.
How do I increase the managed policies per role limit?
Open Service Quotas in US East (N. Virginia), choose AWS Identity and Access Management (IAM), find Managed policies per role and request 25. It is usually approved within minutes.
Do inline policies count toward the managed policies per role limit?
No. Inline policies have their own limit: all of a role's inline policies together can be up to 10,240 characters, whitespace not counted.
What is the difference between a managed and an inline policy?
A managed policy is a standalone policy you can attach to many users, groups and roles, with versions. An inline policy is embedded in one identity and deleted with it.
How many managed policies can be attached to an IAM user?
10 by default, and up to 20 after an automatically approved increase. Putting users into groups is usually the better fix.
How many managed policies can be attached to an IAM group?
10, and that quota cannot be increased. Merge the group's policies or use a second group.
What does "Cannot exceed quota for ACLSizePerRole" mean?
The role's trust policy is longer than allowed, 2,048 characters by default. Raise Role trust policy length to 8,192 or shorten the trust policy with conditions.
What is the maximum size of an IAM managed policy?
6,144 characters, whitespace not counted, and it cannot be raised. Split a larger policy into several.
How do I check my IAM quotas from the CLI?
Run aws iam get-account-summary. AttachedPoliciesPerRoleQuota, AssumeRolePolicySizeQuota and the other keys show the limits that apply to your account.
Why can't I find the IAM quota in Service Quotas?
IAM quotas are listed only in US East (N. Virginia), because IAM is a global service. Switch the console Region and search again.
Does an AWS managed policy count the same as a customer managed policy?
Yes. Each attached managed policy counts as one, whether AWS or you created it.
Can I combine several AWS managed policies into one?
You can copy their documents into one customer managed policy, but your copy will not get the updates AWS makes. Merge your own policies first and keep AWS managed ones attached.
How many policies can an IAM Identity Center permission set have?
Up to 25 AWS managed and customer managed policies plus one inline policy. Each account where it is provisioned must allow that many managed policies per role.
Why does Terraform fail with LimitExceeded on aws_iam_role_policy_attachment?
The role reached its managed policy limit during the apply. Reduce the number of attachments or raise the quota, then apply again.
How many versions can an IAM managed policy have?
Five. Delete an old non-default version before creating a sixth.
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: Security – Specialty (SCS-C03) • CloudOps Engineer – Associate (SOA-C03) • Solutions Architect – Associate (SAA-C03) • Developer – Associate (DVA-C03 from December 1, 2026).
Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:
1. Attaching a policy fails with "Cannot exceed quota for PoliciesPerRole". What is the quickest fix that needs no permission change?
Request an increase of Managed policies per role in Service Quotas (US East, N. Virginia) up to 25; it is approved automatically.
2. A role already has 25 managed policies and needs more permissions. What are the options?
Merge policies into fewer customer managed policies, move role-specific permissions into an inline policy, grant access through resource-based policies, or split the role.
3. Do inline policies count toward the managed policies per role quota?
No; inline policies are limited only by their combined size of 10,240 characters per role.
4. A trust policy listing 40 member accounts fails with ACLSizePerRole. What is the cleanest fix?
Replace the account list with an aws:PrincipalOrgID condition, or raise Role trust policy length to 8,192 characters.
5. Which command shows the IAM quotas that apply to an account?
aws iam get-account-summary, for example AttachedPoliciesPerRoleQuota and AssumeRolePolicySizeQuota in SummaryMap.
6. An IAM group needs an eleventh managed policy. What can you do?
Managed policies per group is fixed at 10, so merge policies or use a second group.
Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.
The deploy ran again ten minutes after it failed: two redundant policies detached, the quota raised to 25 as a safety margin, and the AI feature moved to its own role the same week. The deploy role now has 13 policies and a note in the checklist. "Thirteen," Jake said. "Unlucky?" "Lucky," Ethan said. "Twelve below the ceiling."
📌 If you keep one line from this page
PoliciesPerRole is a count, not a size: remove redundant policies first, raise the limit to 25 in Service Quotas in US East (N. Virginia) if you need room, and beyond that merge into customer managed policies, move role-only permissions inline, or split the role.
20 per role by default, 25 max · 10 per user (20 max) · 10 per group (fixed) · trust policy 2,048 to 8,192 characters.
Revision note. Written October 22, 2026, with the IAM and IAM Identity Center quotas of that date. "Many a little makes a mickle," the proverb says; twenty policies arrive one at a time.