简体   繁体   中英

Getting IndexError: list index out of range error

I have created " CfnUserPool " object using https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cognito/CfnUserPool.html aws document.

I wanted to fetch " Pool Id " of UserPool. It's Id value is - " us-east-1_4kXXXXXXX ". I tried so many options to fetch this value using python but it didn't work.

So I fetched " Pool ARN " value of UserPool, because it has id value in it. Pool ARN is - " arn:aws:cognito-idp:us-east-1:XXXXXXXXXXXX:userpool/us-east-1_4kXXXXXXX " You can see there is "us-east-1_4kXXXXXXX" substring in Pool ARN.

I tried below code to get "us-east-1_4kXXXXXXX" value from Pool ARN -

_cognito_user_pool = _cognito.CfnUserPool(stack, id="pool-id", user_pool_name="user-auth-pool")
_user_pool_id = _cognito_user_pool.attr_arn.split('/')[1]

I was getting "IndexError: list index out of range" error.

I tried to print this ARN value on console and I got this value - ${Token[TOKEN.327]} I don't know why it's printing User pool arn value is in Token format. I think whenever I am trying to fetch it, it is in Token format and that is why I am not able to split it by "/". When we pass ARN value to any resource, it goes in proper format or string format and not in Token format. But if we try to manipulate it, it gives "IndexError: list index out of range" error. since it in token format.

Answer - I have resolved this issue by using UserPool instead of CfnUserPool . UserPool has " user_pool_id " attribute and we can fetch it's id value using this attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM