Amazon Cognito Error : Unable to resolve host cognito-identity.us-east-1.amazonaws.com

Amazon Cognito Error : Unable to resolve host cognito-identity.us-east-1.amazonaws.com

尝试使用 Cognito(在 Android 应用程序中)获取托管在 s3 上的文件,如下所示:

....
         AmazonS3 s3 = new AmazonS3Client(getCredentials(MyActivity.this));
         S3Object object = s3.getObject(new GetObjectRequest("mybucket", "myfile"));
....

public static CognitoCachingCredentialsProvider  getCredentials(Context ctx)
    {
        CognitoCachingCredentialsProvider cognitoProvider = new CognitoCachingCredentialsProvider(
                ctx,
                "us-east-1:xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx", /* Identity Pool ID */
                Regions.US_EAST_1 /* Region */
            );
        return cognitoProvider;
    }

显示此错误:

Unable to execute HTTP request: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname
: I/AmazonHttpClient(3427): java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-east-1.amazonaws.com": No address associated with hostname
: I/AmazonHttpClient(3427):     at java.net.InetAddress.lookupHostByName(InetAddress.java:400)
: I/AmazonHttpClient(3427):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)

有什么问题吗?

您可能忘记包含以下权限:

<uses-permission android:name="android.permission.INTERNET" />

详情请见Set Up the SDK for Android

如果 phone 互联网数据未打开,也会发生此错误。在向云服务发出请求之前,请始终检查设备互联网或数据服务是否已启用/可用。