aws / aws/aws-cdk

IAM: Python type IPrincipal is incompatible with ServicePrincipal

Open
#31,454 6 comments 5 reactions 0 assignees View on GitHub
@aws-cdk/aws-iam bug effort/medium p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

This bug was already reported previously #30431.

Not sure why it was not addressed and the issue closed, so opening a new one.
The AWS plugin in VSCode is quite extensive so it seems to be a very encouraged tool to use for AWS development, but this bug makes the coding experience very poor.

Also the `_statement` parameter looks very weird
```
principal = iam.AccountPrincipal("123456789012")
principal.add_to_principal_policy(_statement=iam.PolicyStatement())
```
and if it's called like that instead of `statement` like it is in `IPrincipal` for a reason it's seems like an ugly hack.

If you think that you are doing the correct thing with regards to python typing then we should start a discussion about it with pyright developers.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Last Known Working CDK Version

_No response_

### Expected Behavior

I'm expecting to not get typing errors when writing the code as it is intended.

### Current Behavior

Raises typing error.

### Reproduction Steps

See #30431

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.154.1 (build febce9d)

### Framework Version

_No response_

### Node.js Version

v20.12.2

### OS

Ubuntu 22.04.4 LTS

### Language

Python

### Language Version

Python 3.12

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in #30431 and inspect the Python IAM entry points named here: IPrincipal, ServicePrincipal, AccountPrincipal.add_to_principal_policy, and PolicyStatement. Confirm the reported pyright error against CDK 2.154.1, then trace the related type definitions and verify that the intended principal-policy call completes without typing errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authorization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.