获取AttributeError:模块'aws_cdk.aws_cognito'没有属性'UserPoolResourceServer'错误

时间:2019-12-12 09:51:40

标签: python amazon-cognito aws-cdk

我正在尝试使用python代码创建cognito的“ CfnUserPoolResourceServer”。根据{{​​3}},我尝试设置“作用域”参数。 根据{{​​3}}文档,范围的类型为““ ResourceServerScopeType的列表”。因此,我尝试如下初始化ResourceServerScopeType对象-

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

但是我遇到了错误-

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

我无法理解如何为CfnUserPoolResourceServer设置“ scopes”参数。请帮帮我。

1 个答案:

答案 0 :(得分:1)

您需要直接使用CfnUserPoolResourceServer

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'
                }
            ]
        )