Skip to content

aws_iam: iam.Role.from_role_name should fail but returns weird info #24503

@hugowschneider

Description

@hugowschneider

Describe the bug

If I accidentally from from_role_name using an role ARN like the code below.

role_arn = "arn:aws:iam::***:role/myrole"

role = iam.Role.from_role_name(
            scope=self,
            id="Role",
            role_name=role_arn,
        )
print(role.role_arn)

The function does not report any error and returns a valid role object with wrong ARN. The snippet will print

arn:aws:iam::***:role/arn:aws:iam::***:role/myrole

which of course is a invalid arn and cannot be used anywhere.

Expected Behavior

Either

throw an exception such as "Role not found" or "Invalid Role Name"

OR

Return the correct role as it does, but with its attributes having valid values.

Current Behavior

The function is returning an object with wrong ARN and not failing as expected.

Reproduction Steps

Just include the above code in a CDK stack.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.67.0 (build b6f7f39)

Framework Version

No response

Node.js Version

v14.21.3

OS

Amazon Linux 2

Language

Python

Language Version

Python 3.9.13

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-iamRelated to AWS Identity and Access ManagementbugThis issue is a bug.effort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions