Nitesh
Nitesh

Reputation: 1637

Getting AttributeError: module 'aws_cdk.aws_cognito' has no attribute 'UserPoolResourceServer' Error

I am trying to create "CfnUserPoolResourceServer" of cognito using python code. As per https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cognito/CfnUserPoolResourceServer.html I am trying to set "scopes" parameter. As per https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolresourceserver.html#cfn-cognito-userpoolresourceserver-scopes document the type of scopes is "List of "ResourceServerScopeType". So I am trying to initialize ResourceServerScopeType object as below -

_rs = _cognito.UserPoolResourceServer()
        _rs1 = _rs.ResourceServerScopeType
        _rs1.Scopes.ScopeName = "access_db_data"
        _rs1.Scopes.ScopeDescription = "access data from table"

But I am getting below error -

AttributeError: module 'aws_cdk.aws_cognito' has no attribute 'UserPoolResourceServer'

I am not able to understand how to setup "scopes" parameter for CfnUserPoolResourceServer. Please help me out.

Upvotes: 0

Views: 2597

Answers (1)

kylevoyto
kylevoyto

Reputation: 489

You need to use CfnUserPoolResourceServer directly.

from aws_cdk import (
    aws_cognito as _cognito,
    core,
)


class CognitoStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        _rs = _cognito.CfnUserPoolResourceServer(
            self, 'rs',
            identifier='identifier_here',
            name='name_here',
            user_pool_id='user_pool_id_here',
            scopes=[
                {
                    'scopeName': 'access_db_data',
                    'scopeDescription': 'access data from table'
                }
            ]
        )

Upvotes: 1

Related Questions