获取AttributeError:模块“aws\u cdk.aws\u cognito”没有属性“UserPoolResourceServer”E

2024-10-02 00:19:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python代码创建cognito的“CfnUserPoolResourceServer”。根据https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cognito/CfnUserPoolResourceServer.html,我试图设置“scopes”参数。 根据https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolresourceserver.html#cfn-cognito-userpoolresourceserver-scopes文档,作用域的类型是“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”参数。请帮帮我


Tags: httpscomawsdocsamazon参数htmllatest
1条回答
网友
1楼 · 发布于 2024-10-02 00:19:48

您需要直接使用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'
                }
            ]
        )

相关问题 更多 >

    热门问题