Package: usermgr
User Management Tools & LibraryOverviewThis is a library and tools for user management.
It provides the following functions.usermgr library for PythonLambda functions for Cognito user managementDynamoDB definition and Lambda functions for Cognito user activity management[Under construction] GUI tool for user managementDescription of each tool and libraryusermgr libraryThis is a Python library for user management.It provides functions such as adding, updating, deleting, and searching users.At the moment, it supports AWS Cognito.It supports both direct operation of Cognito API and operation via Lambda function.Use a Lambda function when you cannot directly operate Cognito from a private subnet.In the future, it is planned to support other user management services. The structure of the library will be kept the same so that it can be used when other services are supported.InstallWhen directly operating Cognito APIpipinstallusermgr[cognito]When operating via Lambda functionpipinstallusermgr[lambda]UsagefromusermgrimportFactoryinstance=Factory.create(Factory.AWS_COGNITO)# For Lambda, use Factory.AWS_LAMBDAinstance.add_user('username','password',{'custom:extra_info':'extra_info'})Please refer to usermgr/base.py for available functions.Cognito user management Lambda functionUsed when operating Cognito via Lambda function from a private subnet.Follow the steps below after moving to the etc folder.1. Create an environment configuration fileCreate the etc/.env file.The settings are as follows.AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_PROFILE should be set according to the aws cli configuration file.NameDescriptionAWS_ACCESS_KEY_IDAccess key IDAWS_SECRET_ACCESS_KEYSecret access keyAWS_PROFILEProfile name in the aws cli configuration fileAWS_REGIONRegion nameACCOUNT_IDAWS account IDROLEIAM role name to be granted to the Lambda functionDYNAMODB_ACTIVITY_POLICYDynamoDB access policy name to be granted to the roleDYNAMODB_NAMEDynamoDB table nameLAMBDA_NAME_ACTIVITYLambda function name for user activity managementLAMBDA_NAME_USERMGRLambda function name for user managementLAMBDA_NAME_DOWNLOADLambda function name for JWKS downloadUSERPOOL_IDCognito user pool IDCLIENT_IDCognito client IDSECRETCognito client secretExample (Modify as needed for your environment)AWS_PROFILE=xxxxAWS_REGION=ap-northeast-1ACCOUNT_ID=xxxxxxROLE=usermgr-lambda-roleDYNAMODB_ACTIVITY_POLICY=usermgr_activity_policyDYNAMODB_NAME=usermgr_activityLAMBDA_NAME_ACTIVITY=usermgr_activityLAMBDA_NAME_USERMGR=usermgrLAMBDA_NAME_DOWNLOAD=usermgr_download_jwksUSERPOOL_ID=ap-northeast-1_xxxxxxCLIENT_ID=xxxxxxSECRET=xxxxx2. IAM role creationexecute the following command in the etc folder.dotenvrun./role/scripts/create_role.sh3. Register Lambda function3-1. Create a Lambda function for user managementexecute the following command in the etc folder.dotenvrun./usermgr/scripts/create_usermgr.sh3-2. Create a Lambda function for JWKS downloadexecute the following command in the etc folder.this function is needed when using Cognito's ID token validation in the private subnet.dotenvrun./download_jwks/scripts/create_function.shPlease incorporate Lambda execution into each project by referring to ./download_jwks/scripts/create_function.sh.3-3. Create a Lambda function for user activity managementexecute the following command in the etc folder.dotenvrun./activity/scripts/create_dynamodb.sh
dotenvrun./activity/scripts/create_function.shPlease regist the Lambda function with PreCreate Token Lambda Trigger in Cognito User Pool.How To Remove the User Management Tools & LibraryFollow the steps below after moving to the etc folder.If you are referring to Lambda from Cognito, remove the Lambda trigger from Cognito before deleting the Lambda function.Replace each name with the one specified in the environment settings.dotenvrunawslambdadelete-function--function-nameusermgr
dotenvrunawslambdadelete-function--function-nameusermgr_dl_jwks
dotenvrunawslambdadelete-function--function-nameusermgr_activity
dotenvrunawsdynamodbdelete-table--table-nameusermgr_activity
dotenvrunawsiamdelete-role--role-nameusermgr-lambda-role
dotenvrunawsiamdelete-policy--policy-nameusermgr_activity_policy