Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iam): AccountPrincipal accepts values which aren't account IDs #20292

Merged
merged 9 commits into from
May 19, 2022
3 changes: 3 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@ removed:@aws-cdk/aws-lambda-event-sources.SelfManagedKafkaEventSourceProps.onFai

# removed kubernetes version from EKS
removed:@aws-cdk/aws-eks.KubernetesVersion.V1_22

# changed the type of AccountPrincipal argument accountId's type to string
incompatible-argument:@aws-cdk/aws-iam.AccountPrincipal.<initializer>
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-iam/lib/principals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ export class AccountPrincipal extends ArnPrincipal {
*/
constructor(public readonly accountId: any) {
super(new StackDependentToken(stack => `arn:${stack.partition}:iam::${accountId}:root`).toString());
if (!cdk.Token.isUnresolved(accountId) && typeof accountId !== 'string') {
throw new Error('accountId should be of type string');
}
this.principalAccount = accountId;
}

Expand Down