AWS CDK: Compound accounts together in an IAM role using CDK

0

I want to create following trust relationship of IAM role using CDK

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::1234:root",
                    "arn:aws:iam::5678:root"
                ]
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

But instead I am getting

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::1234:root"
            },
            "Action": "sts:AssumeRole"
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::5678:root"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

The code I am using

const account1 = new ArnPrincipal("1234");
const account2 = new ArnPrincipal("5678");

const role = new Role(this, 'myRoleId', {
    roleName: 'myRoleName',
    assumedBy: new CompositePrincipal(account1, account2),
});

role.addToPolicy(
    new PolicyStatement({
        actions: ['abcd', 'defg'],
        resources: ['*'],
    })
);

This is causing the Role trust policy length to go over the limit. I have increased the limit with AWS but I have already increased it to the hard limit AWS has set in place.

1 回答
0
已接受的回答

Seems there is an open bug about it: https://github.com/aws/aws-cdk/issues/23765

profile picture
专家
已回答 9 个月前
profile picture
专家
已审核 2 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则