简体   繁体   中英

Android AWS SDK : Cognito Identity not was not found in region metadata

I am writing a simple test app to connect to AWS using android APP. I am providing identity pool credentials through the CognitoCachingCredentialsProvider Constructor. On the AWS console, I have created an Identity Pool and I have checked "Enable access to Unauthenticated identities". A corresponding IAM role is created with basic access to AWS services.

However, when I run my android code, I am always getting the error: "{cognito-identity, us-west-2} was not found in region metadata, trying to construct an endpoint using the standard pattern for this region: 'cognito-identity.us-west-2.amazonaws.com'.

I have followed all the instructions given in aws docs. I am not able understand where I am going wrong. If any one has experienced this or knows a solution for what I am doing wrong, I will appreciate the help very much.

The android code for CognitoCachingCredentialsProvider constructor is copied from SourceCode section of Identity Pool Console of AWS. The android code I have written is as follows:

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import com.amazonaws.auth.CognitoCachingCredentialsProvider;
import com.amazonaws.regions.Regions;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button b = (Button)findViewById(R.id.fhButton);

    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showClick();
        }
    });

}

public void showClick(){
    Log.i("TEST", "Hurray!");

    new AsyncTask(){
        @Override
        protected Object doInBackground(Object[] objects) {
            // Initialize the Amazon Cognito credentials provider
            CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                    getApplicationContext(),
                    "us-west-2:XXXXXXXXXX", // Identity Pool ID
                    Regions.US_WEST_2 // Region
            );
            Log.i("TEST",credentialsProvider.getIdentityId());

            return null;
        }
    }.execute();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

Do you see the identity ID on logcat? From this post on the AWS forums, it might just be that the message is misleading, but the call actually works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM