简体   繁体   English

Android AWS SDK:在区域元数据中找不到Cognito身份

[英]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. 我正在编写一个简单的测试应用程序,以使用android APP连接到AWS。 I am providing identity pool credentials through the CognitoCachingCredentialsProvider Constructor. 我正在通过CognitoCachingCredentialsProvider构造函数提供身份池凭据。 On the AWS console, I have created an Identity Pool and I have checked "Enable access to Unauthenticated identities". 在AWS控制台上,我已经创建了一个身份池,并选中了“启用对未经身份验证的身份的访问”。 A corresponding IAM role is created with basic access to AWS services. 将创建具有对AWS服务的基本访问权限的相应IAM角色。

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'. 但是,当我运行我的android代码时,我总是收到错误消息:“在区域元数据中找不到{{cognito-identity,us-west-2},试图使用该区域的标准模式来构建端点:'cognito -identity.us-west-2.amazonaws.com”。

I have followed all the instructions given in aws docs. 我已按照AWS文档中给出的所有说明进行操作。 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. 从AWS身份池控制台的SourceCode部分复制了CognitoCachingCredentialsProvider构造函数的android代码。 The android code I have written is as follows: 我编写的android代码如下:

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? 您在logcat上看到身份ID吗? From this post on the AWS forums, it might just be that the message is misleading, but the call actually works. 在AWS论坛上的这篇文章中 ,可能只是该消息具有误导性,但该呼叫实际上有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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