# 错误：策略中的主体无效：'AWS: arn:aws:iam::123456789012:role/NonExistentRole'

- **ID:** `policy/aws-iam-role-trust-policy-invalid-principal`
- **领域:** policy
- **类别:** config_error
- **错误码:** `MalformedPolicyDocument`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

IAM角色信任策略引用了一个不存在或拼写错误的主体（例如另一个角色或账户），导致策略被拒绝。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| AWS IAM API 2010-05-08 | active | — | — |
| aws-cli 2.14.0 | active | — | — |

## 解决方案

1. ```
   通过运行以下命令验证ARN是否存在：aws iam get-role --role-name NonExistentRole。如果不存在，则创建角色或更正ARN。示例：将ARN更改为arn:aws:iam::123456789012:role/ExistingRole。
   ```
2. ```
   如果信任策略应该允许账户中的任何角色，则使用通配符主体如'AWS: *'，但这在安全上有风险。
   ```

## 无效尝试

- **Use the role ID instead of ARN in the principal** — IAM policies require ARN format for principals; role IDs are not accepted in principal elements. (100% 失败率)
- **Add the principal as a service (e.g., 'Service: ec2.amazonaws.com') even if it's a role** — Service principals are for AWS services, not IAM roles; mixing types causes validation errors. (90% 失败率)
