# 错误：放置 IAM 策略时出错：LimitExceeded：不能超过 PolicySize 的配额：6144

- **ID:** `policy/aws-iam-policy-size-exceeded`
- **领域:** policy
- **类别:** resource_error
- **错误码:** `LimitExceeded`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

AWS IAM 策略大小限制为客户管理策略 6144 个字符；策略文档因语句过多、ARN 过长或条件冗长而超出此限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| AWS IAM API 2010-05-08 | active | — | — |
| AWS CLI v2.15.0 | active | — | — |
| Terraform AWS Provider v5.40.0 | active | — | — |

## 解决方案

1. ```
   将具有重叠操作的多个语句合并为一个语句，使用操作和资源列表。例如，将 's3:GetObject' 和 's3:PutObject' 合并为一个语句，包含 's3:GetObject', 's3:PutObject'。
   ```
2. ```
   使用策略变量如 ${aws:username} 减少硬编码 ARN 长度，并删除冗余条件。
   ```
3. ```
   将策略拆分为多个托管策略附加到同一角色；每个托管策略有自己的 6144 字符限制。
   ```

## 无效尝试

- **** — Removing whitespace or minifying JSON does not reduce the character count significantly; the error is about logical size, not formatting. (90% 失败率)
- **** — Splitting the policy into multiple inline policies on the same role still counts toward the total role policy size limit (10240 characters). (70% 失败率)
- **** — Using a wildcard instead of listing individual resources may violate least-privilege policies and still hit size limits if the condition is verbose. (50% 失败率)
