When you need this
A pipeline that has been adding permissions to a role for two years suddenly fails with:
LimitExceeded: Cannot exceed quota for PolicySize: 6144
LimitExceeded: Cannot exceed quota for PoliciesPerRole: 10
LimitExceeded: Cannot exceed quota for ACLSizePerRole: 2048
LimitExceeded: A managed policy can have up to 5 versions.
PackedPolicyTooLarge: Packed policy consumes 112% of allotted space
Each message maps to a different quota with a different fix. Some can be raised, most can't. This sheet covers the ones that block real deployments.
The quotas that matter
Values below are the long-standing defaults. AWS changes quotas occasionally, so confirm with get-account-summary (next section) or the IAM quotas page before planning around a number.
| Error text / symptom | Quota | Default | Adjustable? |
|---|---|---|---|
PolicySize: 6144 | Customer managed policy document size | 6,144 characters | No |
PoliciesPerRole: 10 | Managed policies attached to a role | 10 | Yes, by request (up to 20) |
| Same error for a user or group | Managed policies attached to a user or group | 10 | Yes, by request |
Maximum policy size of 10240 bytes exceeded for role | Total size of all inline policies on one role | 10,240 characters | No |
ACLSizePerRole: 2048 | Role trust policy size | 2,048 characters | Yes, by request (up to 4,096) |
A managed policy can have up to 5 versions | Versions per managed policy | 5 | No |
RolesQuota reached | Roles per account | 1,000 | Yes |
PackedPolicyTooLarge | Session policies + session tags after compression | Percentage of an internal limit | No |
| SCP fails to save | Service control policy size | 5,120 characters | No |
IAM doesn't count whitespace toward managed policy size, so pretty-printing isn't what pushed you over. Inline policy size counting differs and AWS doesn't document it precisely, so leave margin.
See where an account stands
aws iam get-account-summary --query "SummaryMap" --output table
Useful keys in SummaryMap:
| Key | Meaning |
|---|---|
Roles / RolesQuota | Roles in use vs quota |
Policies / PoliciesQuota | Customer managed policies vs quota |
AttachedPoliciesPerRoleQuota | Current per-role attachment quota (shows whether an increase was granted) |
PolicySizeQuota | Managed policy size quota |
AssumeRolePolicySizeQuota | Trust policy size quota |
PolicyVersionsInUseQuota | Total policy versions allowed in the account |
IAM is a global service. In accounts where IAM quotas appear in Service Quotas, query them in us-east-1:
aws service-quotas list-service-quotas --service-code iam --region us-east-1 \
--query "Quotas[].{Name:QuotaName,Code:QuotaCode,Value:Value,Adjustable:Adjustable}" --output table
If that returns nothing, request increases through the IAM quotas page in the console or a support case.
Find the roles closest to the limits
Attachment count per role:
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)")
[ "$N" -ge 8 ] && echo "$N $R"
done | sort -rn
Compressed size of every customer managed policy's default version (whitespace removed, close to how IAM counts it):
import boto3, json
iam = boto3.client("iam")
rows = []
for page in iam.get_paginator("list_policies").paginate(Scope="Local"):
for p in page["Policies"]:
doc = iam.get_policy_version(PolicyArn=p["Arn"], VersionId=p["DefaultVersionId"])
size = len(json.dumps(doc["PolicyVersion"]["Document"], separators=(",", ":")))
rows.append((size, p["PolicyName"], p["AttachmentCount"]))
for size, name, att in sorted(rows, reverse=True)[:20]:
print(f"{size:>6} {size/6144:>5.0%} attached={att:<3} {name}")
Total inline policy size on a role:
import boto3, json, sys
iam = boto3.client("iam")
role = sys.argv[1]
total = 0
for name in iam.list_role_policies(RoleName=role)["PolicyNames"]:
doc = iam.get_role_policy(RoleName=role, PolicyName=name)["PolicyDocument"]
n = len(json.dumps(doc, separators=(",", ":")))
total += n
print(f"{n:>6} {name}")
print(f"{total:>6} total ({total/10240:.0%} of 10,240)")
Fixes, by error
PolicySize: 6144
Shrink the document without granting more:
| Technique | Before | After |
|---|---|---|
| Merge statements with the same Effect, Resource and Condition | Five statements, one action each | One statement, five actions |
| Use action prefixes carefully | s3:GetObject, s3:GetObjectVersion, s3:GetObjectTagging... | s3:GetObject* (check the expanded list first) |
| Replace ARN lists with a pattern or tag condition | 40 bucket ARNs | arn:aws:s3:::team-a-* or aws:ResourceTag/team |
Drop Sid values you don't use | "Sid": "AllowReadOnlyAccessToReportingBucketsForEtl" | No Sid |
| Split by function | One "app" policy | app-s3, app-sqs, app-kms |
Warning
Wildcards widen access to actions AWS adds later.
s3:Get*includess3:GetObjectAcland anything introduced next year. Expand the wildcard in the IAM policy editor or with Access Analyzer policy validation and confirm the list before you ship it.
Validate the rewrite:
aws accessanalyzer validate-policy --policy-type IDENTITY_POLICY \
--policy-document file://app-s3.json \
--query "findings[].{Type:findingType,Issue:issueCode,Detail:findingDetails}"
PoliciesPerRole: 10
Before requesting an increase, look for attachments that are mostly redundant: AWS managed ReadOnlyAccess alongside several service read policies, or three versions of the same team policy. Consolidating into fewer customer managed policies (each under 6,144) is usually cleaner than going to 20. Requesting the increase is fine when the role genuinely spans many services, but remember the 6,144 limit per policy still applies.
Inline policy total exceeded
Inline policies share one 10,240-character budget per role. Move them to customer managed policies, which each get their own 6,144:
aws iam get-role-policy --role-name etl-runner --policy-name legacy-inline \
--query PolicyDocument > legacy.json
aws iam create-policy --policy-name etl-runner-legacy --policy-document file://legacy.json
aws iam attach-role-policy --role-name etl-runner \
--policy-arn arn:aws:iam::111122223333:policy/etl-runner-legacy
aws iam delete-role-policy --role-name etl-runner --policy-name legacy-inline
Attach the managed policy before deleting the inline one so there's no window without permissions.
ACLSizePerRole: 2048 (trust policy)
Trust policies grow when every CI repository or account is listed separately. Options:
- Use a single condition with a list or wildcard:
"token.actions.githubusercontent.com:sub": "repo:my-org/*:ref:refs/heads/main"withStringLike. - Trust an organization instead of listing accounts: principal
"AWS": "*"with"aws:PrincipalOrgID": "o-abc123", plus a narrower condition such asaws:PrincipalArn. - Request the increase to 4,096 if the list is genuinely needed.
Caution
A trust policy with
"Principal": {"AWS": "*"}and a mistyped or missing condition lets any AWS account assume the role. Test changes with a principal outside the org and confirm the denial before relying on them.
5 policy versions
Every create-policy-version keeps the old one. Delete the oldest non-default version first:
ARN=arn:aws:iam::111122223333:policy/app-s3
aws iam list-policy-versions --policy-arn $ARN \
--query "Versions[?IsDefaultVersion==\`false\`] | sort_by(@,&CreateDate)[0].VersionId" --output text \
| xargs -I{} aws iam delete-policy-version --policy-arn $ARN --version-id {}
Terraform and CloudFormation handle this for you on update. The error usually comes from scripts that call the API directly.
PackedPolicyTooLarge
STS compresses session policies and session tags into one packed blob. The error shows the percentage used. Causes:
- Too many or too long session tags (identity provider passing every group as a tag).
- A large inline session policy passed with
--policy, or many--policy-arns.
Fixes: pass fewer tags, shorten tag values, use managed session policies (--policy-arns, up to 10) instead of a big inline document, and check the PackedPolicySize value returned by assume-role while testing:
aws sts assume-role --role-arn arn:aws:iam::111122223333:role/reporting \
--role-session-name test --policy file://session.json \
--query "PackedPolicySize"
Prevent it next time
- Run the size scripts in CI and fail the build at 80% of a quota, not at 100%.
- Keep one purpose per customer managed policy and name it after that purpose.
- Use tag-based conditions and patterns instead of growing ARN lists.
- Use IAM Access Analyzer unused access findings to remove permissions as well as add them.
- Record quota increases (attachments, trust size) in your account baseline so new accounts get the same limits.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get