aws-cdkaws-cdk-typescript

AWS CDK how to remove "role" prefix in ARN


AWS CDK is adding ROLE prefix in the ARN , is there a way to remove that .. Below is the CDK code

arn:aws:iam::XXXXXXX:role/edo-dps-deng-iam-crossaccount-sqs-access-dev

sf_iam_role = _iam.Role(
    scope=self,
    id=f"edo-dps-deng-iam-crossaccount-sqs-access-{deploy_env}-id",
    assumed_by=_iam.CompositePrincipal(
        _iam.ServicePrincipal("lambda.amazonaws.com"),
        _iam.ServicePrincipal("firehose.amazonaws.com"),
        _iam.ServicePrincipal("sqs.amazonaws.com"),
    ),
    role_name=f"edo-dps-deng-iam-crossaccount-sqs-access-{deploy_env}",
    path=None,
    inline_policies={
        f"edo-dps-deng-{deploy_env}-sofa-iam-role-policy": _iam.PolicyDocument.from_json(
            json_data
        )
    },
)


Solution

  • No, it's not possible to remove, as that is the required syntax for IAM Role ARNs. Here is the documentation.

    arn:aws:iam::account:role/role-name-with-path