Get Disabled user from Cognito UserPool by ListUser API

Code profile = ‘aws-cli-profile’ session = Session(profile_name=profile) cognito = session.client(‘cognito-idp […]

広告ここから
広告ここまで

目次

    Code

    profile = 'aws-cli-profile'
    session = Session(profile_name=profile)
    cognito = session.client('cognito-idp')
    response = cognito.list_users(
        UserPoolId='us-east-1_XXXXXXX',
        Filter="status='Disabled'"
    )
    for data in response['Users']:
        print(data['Username'])
        print(data['Enabled'])
    

    Result

    $ python test.py 
    development
    False
    dev_hideokamoto
    False
    

    Get Activated Users

    To get users who activated.

    profile = 'aws-cli-profile'
    session = Session(profile_name=profile)
    cognito = session.client('cognito-idp')
    response = cognito.list_users(
        UserPoolId='us-east-1_XXXXXXX',
        Filter="cognito:user_status='CONFIRMED'"
    )
    for data in response['Users']:
        if data['Enabled']:
            print(data['Username'])
            print(data['Enabled'])
            print(data['UserStatus'])
    

    Results

    $ python test.py 
    development
    True
    CONFIRMED
    dev_hideokamoto
    True
    CONFIRMED
    

    Tips:Filter can search only one attributes

    If you want to search by multiple attributes, you have to use loop and if.

    広告ここから
    広告ここまで

    Random posts

    Home
    Search
    Bookmark