[Python] My boto3 code gives Success response despite of no successful updates on console

Discussão em 'Python' iniciado por Stack, Março 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following code to sign up a user on AWS cognito.

    async def _sign_up(self, preferred_username: str, username: str, password: str):
    '''
    Sign up a user with Cognito
    :param username -> user's username (either email or phone no.)
    :password -> user's password
    :return -> Success Response on successful signup.
    '''
    try:
    signup_response = self._cognito_client.sign_up(
    ClientId = os.getenv("AWS_COGNITO_APP_CLIENT_ID"),
    Username = username,
    Password = password,
    UserAttributes = [{'Name': 'preferred_username', 'Value':f'{preferred_username}'}]
    )

    if signup_response.get('ResponseMetadata').get('HTTPStatusCode') == 200:
    try:
    confirm_signup_response = self._cognito_client.admin_confirm_sign_up(
    UserPoolId = os.getenv("AWS_COGNITO_USER_POOL_ID"),
    Username = username,
    )

    if confirm_signup_response.get("ResponseMetadata").get("HTTPStatusCode") == 200:

    signin_response = await self._sign_in(
    username = username,
    password = password
    )
    logger.debug(signin_response)
    return signin_response

    except self._cognito_client.exceptions.NotAuthorizedException:
    return Exception("Invalid username or password.")
    except self._cognito_client.exceptions.UserNotFoundException:
    return Exception("User not found.")
    except self._cognito_client.exceptions.TooManyRequestsException:
    return Exception("Request limit exceeded.")
    except self._cognito_client.exceptions.InternalErrorException:
    return Exception("Something went wrong. Please try after sometime.")
    except Exception as e:
    return Exception("Failed to Signin. Please try after some time.", str(e))
    except self._cognito_client.exceptions.UsernameExistsException:
    return Exception("The username already exists.")
    except self._cognito_client.exceptions.TooManyRequestsException:
    return Exception("Request limit exceeded.")
    except self._cognito_client.exceptions.InternalErrorException:
    return Exception("Something went wrong. Please try after sometime.")
    except Exception as e:
    return Exception("Failed to SignUp. Please try after some time.", str(e))


    My server console shows a 200 OK response when I hit the API call. But my console doesn't show any new users. Moreover, I get an empty object as output. What can be the issue? I've checked the _cognito_client config as well. It is alright.

    Continue reading...

Compartilhe esta Página