当前位置: 代码迷 >> Android >> 无法从Android访问AWS S3
  详细解决方案

无法从Android访问AWS S3

热度:68   发布时间:2023-08-04 12:06:53.0

得到异常:

Unable to execute HTTP request: Unable to resolve host "cognito-identity.eu-central-1.amazonaws.com": No address associated with hostname
Unable to resolve host "cognito-identity.eu-central-1.amazonaws.com": No address associated with hostname

代码如下:

        // Initialize the Amazon Cognito credentials provider
        CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(), // Application Context
                getResources().getString(R.string.AWS_IdentityPoolId), // Identity Pool ID
                Regions.EU_CENTRAL_1 // Region enum
        );

这是地区的“公正”问题。 因为我的Cognito在爱尔兰,而我的Bucket在弗兰克福特,所以很容易混淆。 因此,您可能会在区域上保持谨慎。 在可能的情况下:

// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
       getApplicationContext(), // Application Context
       getResources().getString(R.string.AWS_IdentityPoolId), // Identity Pool ID
       Regions.EU_WEST_1 // Region enum
);

仅供参考,EU_CENTRAL_1(法兰克福)尚无法使用Cognito身份。 检出 。 就像Anthony所说的那样,Cognito身份不必与其他服务位于同一地区。 请始终选择靠近您的区域,以获得更好的体验。

  相关解决方案