Closed SpielerNogard closed 1 week ago
@SpielerNogard Good morning. I tried to reproduce the issue in TypeScript
(even though the issue was reported in Python) to compare the behavior.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as cognito from 'aws-cdk-lib/aws-cognito';
import * as cognitoidp from '@aws-cdk/aws-cognito-identitypool-alpha';
export class TypescriptStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const userPool = cognito.UserPool.fromUserPoolArn(this, 'CognitoUserPool', 'arn:aws:cognito-idp:<<REGION>>:<<ACCOUNT-ID>>:userpool/<<REGION>>_<<SOME-ID>>');
const userPoolClient = cognito.UserPoolClient.fromUserPoolClientId(this, 'UserPoolClientId', '<<APP-CLIENT-ID>>');
const identityPool = new cognitoidp.IdentityPool(this, 'IdentityPool', {
identityPoolName: 'IdentityPool',
authenticationProviders: {
userPools: [
new cognitoidp.UserPoolAuthenticationProvider({
userPool: userPool,
userPoolClient: userPoolClient
})
]
},
roleMappings: [
{
mappingKey: 'cognito',
providerUrl: cognitoidp.IdentityPoolProviderUrl.userPool(userPool, userPoolClient),
useToken: true
}
],
allowUnauthenticatedIdentities: false
});
}
}
The Visual Studio Code IDE itself flagged the error Argument of type 'IUserPool' is not assignable to parameter of type 'UserPool'. Type 'IUserPool' is missing the following properties from type 'UserPool': userPoolProviderName, userPoolProviderUrl, triggers, addTrigger, and 17 more.ts(2345)
at line providerUrl: cognitoidp.IdentityPoolProviderUrl.userPool(userPool, userPoolClient),
.
Upon investigating further:
UserPool
.cognito.UserPool.fromUserPoolArn()
is typed to interface IUserPool
.Per inheritance rules, it is possible to assign parent class object implementing an interface, to interface object type; but not vice versa, due to obvious reasons.
Hence, the error. The CDK Python code is translated to TypeScript code via JSII, hence a different error message. But I'm assuming the reasoning is same.
I will discuss this with the team for any workarounds.
Thanks, Ashish
Thanks for the answer.
Thats bad, since we cant recreate the userpool in the stack, because we have too much users, and this error interrupts us also with the plan to go to python3.12
Hope its possible to find a workaround 🤞
That's correct!
But if we look at its implementation:
we just need the userPoolProviderName
attribute of the userPool, which is not available in IUserPool.
https://github.com/aws/aws-cdk/blob/c3003ab41f0efc763f39eb2cab490c8a005e146b/packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts#L757-L803
To fix this bug:
userPoolProviderName
in IUserPooluserPoolProviderName
for an existing user pool.userPool(userPool: UserPool
to userPool(userPool: IUserPool
I'll take this.
Hi @sakurai-ryo
Please note adding new attributes to IUserPool would be a breaking change and we should avoid that as aws-cognito is a stable module. I am requesting input from our maintainers for this issue so we'll know how to address that.
Just one point of clarification: adding attributes is not a breaking change. The proposed change is OK on our end.
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.
Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.
Describe the bug
Our Userpool and clients are created outside our application. We now want to attach a identity pool to this userpool. Today i updated from version
aws-cdk-aws-cognito-identitypool-alpha==2.96.0a0
toaws-cdk-aws-cognito-identitypool-alpha == 2.141.0a0
and changed the role_mappings accordingly. While runningcdk synth
i get the error:TypeError: type of argument user_pool must be aws_cdk.aws_cognito.UserPool; got jsii._reference_map.InterfaceDynamicProxy instead
Expected Behavior
Since the
UserPoolAuthenticationProvider
is able to handle imported userpools and clients, theIdentityPoolProviderUrl
should also beCurrent Behavior
Reproduction Steps
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.142.1 (build ed4e152)
Framework Version
No response
Node.js Version
v21.1.0
OS
Mac OS 14.5 (23F79)
Language
Python
Language Version
3.8.18 3.12.0 3.11.6
Other information
No response