jeudi 19 février 2015

Inconsistent authorization of AWS Java API

I am trying to use AWS Java API to create a volume from my Java program. Here is the sample code.



String accessKey = "XXXXXXXXXXXXXX";
String secretKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonEC2Client client = new AmazonEC2Client(credentials);
client.setEndpoint("ec2.ap-northeast-1.amazonaws.com:443");
CreateVolumeRequest request = new CreateVolumeRequest(1, "ap-northeast-1c");
CreateVolumeResult volumeResponse = client.createVolume(request);


When I run this code on an AWS instance, this is running fine for the given credentials.


But If I run the same program with the same credentials from a machine on my corporate network. This is giving an exception.



com.amazonaws.AmazonServiceException: AWS was not able to validate the provided access credentials (Service: AmazonEC2; Status Code: 401; Error Code: AuthFailure; Request ID: xxxxxxx)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1077)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:725)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:460)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:295)
at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:9393)
at com.amazonaws.services.ec2.AmazonEC2Client.createVolume(AmazonEC2Client.java:6707)


What could be the reason for this failure? One observation is that this is not happening consistently.





Aucun commentaire:

Enregistrer un commentaire