Reputation: 1527
I'm trying to download from my Amazon S3 bucket on Android, although i'm getting this error:
java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-west-2.amazonaws.com": No address associated with hostname
on this line
Download down = manager.download(AWSClientManager.S3_BUCKET_NAME, fileToDownload, file);
I'm unsure why it would be using us-west-2 when the default for my CognitoCachingCredentialsProvider is us-east-1
Even so, the following locatinos for my s3 storage have the exact same files:
https://console.aws.amazon.com/s3/home?region=us-east-1
https://console.aws.amazon.com/s3/home?region=us-west-2
I have no idea why I am getting the error above, can somebody help please?
Hi @Mark, My CognitoCachingCredentialsProvider is set to US_EAST_1
I am using AmazonS3Client to download S3 files.. I think this might be the issue. I am explicitly setting the region, although it seems to completely disregard this.
This is my code where it errors:
private S3TaskResult downloadResources(String fileToDownload) {
S3TaskResult result = new S3TaskResult();
File file = new File(downloadDirectory, fileToDownload);
try {
manager.getAmazonS3Client().setRegion(com.amazonaws.regions.Region.getRegion(Regions.US_EAST_1));
Download down = manager.download(AWSClientManager.S3_BUCKET_NAME, fileToDownload, file);
down.addProgressListener(this);
down.waitForCompletion();
} catch (Exception e) {
// TODO: FIGURE OUT WHY IT ERRORS HERE :(
result.setErrorMessage(e.getMessage());
}
return result;
}
Upvotes: 1
Views: 3670
Reputation: 993
The problem seems to be that you are trying to use Amazon Cognito is us-west-2.
java.net.UnknownHostException: Unable to resolve host "cognito-identity.us-west-2.amazonaws.com": No address associated with hostname
Currently, Amazon Cognito is only available in us-east-1, eu-west-1, and ap-northeast-1.
This does not mean you cannot use Cognito credentials to access S3 buckets in other regions, you simply need set Cognito to use one of the above mentioned regions (and set up your identity pool in that region). Then set your S3 client to use whichever region your bucket is in.
Make sure you are setting up your Credentials Provider with the correct region:
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(), // Context
"IDENTITY_POOL_ID", // Identity Pool ID
Regions.US_EAST_1 // Region
);
As described here: http://docs.aws.amazon.com/cognito/devguide/identity/getting-credentials/
Upvotes: 4