diff --git a/packages/aws-cdk-lib/aws-iam/lib/private/imported-role.ts b/packages/aws-cdk-lib/aws-iam/lib/private/imported-role.ts index 012ac9ac97fc6..34c56951c280e 100644 --- a/packages/aws-cdk-lib/aws-iam/lib/private/imported-role.ts +++ b/packages/aws-cdk-lib/aws-iam/lib/private/imported-role.ts @@ -46,6 +46,8 @@ export class ImportedRole extends Resource implements IRole, IComparablePrincipa public addToPrincipalPolicy(statement: PolicyStatement): AddToPrincipalPolicyResult { if (!this.defaultPolicy) { const useUniqueName = FeatureFlags.of(this).isEnabled(IAM_IMPORTED_ROLE_STACK_SAFE_DEFAULT_POLICY_NAME); + // To preserve existing policy names, use Names.uniqueResourceName() only when exceeding the limit of policy names + // See https://github.com/aws/aws-cdk/pull/27548 for more const prefix = 'Policy'; let defaultDefaultPolicyName = useUniqueName ? `${prefix}${Names.uniqueId(this)}`