Home > Software design >  Call ListUsers (amazon cognito) in Android Java
Call ListUsers (amazon cognito) in Android Java

Time:12-07

How do I exactly call ListUsers from Android Studo (java) ? : https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html#API_ListUsers_RequestSyntax

I am using the following code to initialise, I can also call my REST api.

 try {
            // Add these lines to add the `AWSApiPlugin` and `AWSCognitoAuthPlugin`
            Amplify.addPlugin(new AWSApiPlugin());
            Amplify.addPlugin(new AWSCognitoAuthPlugin());
            Amplify.configure(GlobalApplication.getAppContext());

            Log.i("MyAmplifyApp", "Initialized Amplify.");
        } catch (AmplifyException error) {
            Log.e("MyAmplifyApp", "Could not initialize Amplify.", error);

            
        }

My goal is to retreive all my cognito userpool usernames

CodePudding user response:

I created a lambda function to do the same for me:

 app.get(path   "/users", function(req, res) {

  
  const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider()
  var params = {
    UserPoolId: "eu-west-1_..........", 
    Limit: '10',
  };
  cognitoidentityserviceprovider.listUsers(params, function(err, data) {
    if (err) {
      return res.status(500).json(err)
    }
    res.json({users: data.Users});
  });
});

CodePudding user response:

To build an Android Native App that can invoke AWS Services, use the new AWS SDK for Kotlin. Here is a new tutorial that shows you how to use Android Studio to build an Android App that invokes Amazon DynamoDB and SNS. It will show you how to get up and running:

Creating your first Native Android application using the AWS SDK for Kotlin

Because you want to use Cognito in your app, see the Cognito Kotlin examples:

https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/kotlin/services/cognito/src/main/kotlin/com/kotlin/cognito

So simply follow the above tutorial to create an Android app in Android Studio, replace DynamoDB and SNS with Cognito and build your Native Android app.

To learn more about the AWS SDK for Kotlin, see the DEV Guide:

Get started with the SDK for Kotlin

  • Related