Search code examples
amazon-web-servicesamazon-ec2aws-lambdaamazon-cognitoaws-amplify

AWS Amplify - What is the correct way of storing a user's uuid in cognito after successfully signing up?


I'm using the AWSMobileClient to signup a new user. After they successfully sign up I would like to store their unique uuid aka "sub" id in my SQL database.

AWSMobileClient.getInstance().signUp(username, password, attributes, null, new 
Callback<SignUpResult>() {
@Override
public void onResult(final SignUpResult signUpResult) {
    runOnUiThread(new Runnable() {
    @Override
    public void run() {
        //Successful signing up a new user
        //What would I do here?
    }
});
}

@Override
public void onError(Exception e) {
    Log.e(TAG, "Sign-up error", e);
}

The user successfully signs up, would I make a post request to my database in the callback method? What happens if the user's network fails during midcall or something else happens and the post request doesn't successfully record the user's uuid. What would be the correct way of doing this?


Solution

  • Cognito has a post confirmation trigger. You can use that trigger to call a lambda function which updates your database. Since it all happens within AWS, there is less chance of network failures.

    More info on the flow can be found here