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

aws_iam: item 0 is not compatible with the IManagedPolicy protocol because it has no method named '__jsii_proxy_class__' #4667

Closed
1 task
CollinAlpert opened this issue Oct 11, 2024 · 5 comments
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort p2

Comments

@CollinAlpert
Copy link

Describe the bug

When creating an IAM role, the deployment fails due to an issue with the IManagedPolicy protocol. I noticed this bug after updating the CDK dependency, however now even going back to an older version does not fix the issue.

I only notice this when the deployment is run via GitHub Actions, locally (macOS Silicon) the issue is not reproducible.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

The deployment succeeds and the changes are applied.

Current Behavior

The deployment fails with the following stack trace:

Traceback (most recent call last):
  File "/home/runner/work/id-database/id-database/celery_project/app.py", line 311, in <module>
    IdDatabaseFargateStack(app, f"IdDatabaseFargateStack{os.getenv('CDK_POSTFIX')}", env=env, stack_name=f"IdDatabaseFargateStack{os.getenv('CDK_POSTFIX')}")
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/id-database/id-database/celery_project/app.py", line 79, in __init__
    ecs_task_execution_role = iam.Role(
                              ^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/jsii/_runtime.py", line 118, in __call__
    inst = super(JSIIMeta, cast(JSIIMeta, cls)).__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/aws_cdk/aws_iam/__init__.py", line 12921, in __init__
    props = RoleProps(
            ^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/aws_cdk/aws_iam/__init__.py", line 10751, in __init__
    check_type(argname="argument managed_policies", value=managed_policies, expected_type=type_hints["managed_policies"])
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/aws_cdk/aws_iam/__init__.py", line 881, in check_type
    typeguard.check_type(value=value, expected_type=expected_type, collection_check_strategy=typeguard.CollectionCheckStrategy.ALL_ITEMS) # type:ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/typeguard/_functions.py", line 106, in check_type
    check_type_internal(value, expected_type, memo)
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/typeguard/_checkers.py", line 861, in check_type_internal
    checker(value, origin_type, args, memo)
  File "/opt/hostedtoolcache/Python/3.12.7/x64/lib/python3.12/site-packages/typeguard/_checkers.py", line 433, in check_union
    raise TypeCheckError(f"did not match any element in the union:\n{formatted_errors}")
typeguard.TypeCheckError: list did not match any element in the union:
  Sequence[aws_cdk.aws_iam.IManagedPolicy]: item 0 is not compatible with the IManagedPolicy protocol because it has no method named '__jsii_proxy_class__'
  NoneType: is not an instance of NoneType
Subprocess exited with error 1

Reproduction Steps

This is the problematic code:

ecs_task_execution_role = iam.Role(
    self,
    "ecsTaskExecutionRole",
    assumed_by=iam.ServicePrincipal("ecs-tasks.amazonaws.com"),
    managed_policies=[
        iam.ManagedPolicy.from_aws_managed_policy_name("service-role/AmazonECSTaskExecutionRolePolicy")
    ]
)

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.162.0

Framework Version

No response

Node.js Version

20.17.0

OS

Linux

Language

Python

Language Version

3.12.7

Other information

No response

@CollinAlpert CollinAlpert added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2024
@khushail khushail self-assigned this Oct 11, 2024
@khushail
Copy link
Contributor

@CollinAlpert , thanks for reaching out.

Yes, I tried to locally repro the issue but it succeeded in deployment.

Although from the error it looks like its related to JSII repo. Trying to repro it using github actions though.

@khushail
Copy link
Contributor

@CollinAlpert , team is tracking this issue -aws/aws-cdk#31749 and this is related to the issue you are facing. So I am moving this issue to JSII Repo for further action.

@khushail khushail added effort/medium Medium work item – a couple days of effort and removed needs-reproduction This issue needs reproduction. labels Oct 14, 2024
@khushail khushail transferred this issue from aws/aws-cdk Oct 14, 2024
@khushail khushail removed their assignment Oct 14, 2024
@medley56
Copy link

medley56 commented Oct 14, 2024

I think #4657 is related to this. With the massive typeguard bump in aws-cdk 2.158, I suspect there will be a lot of these issue coming out of the woodwork.

@mrgrain
Copy link
Contributor

mrgrain commented Oct 15, 2024

Same as #4658 we are tracking this over there.

@mrgrain mrgrain closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2024
Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – a couple days of effort p2
Projects
None yet
Development

No branches or pull requests

4 participants