2017-07-11 6 views
0

J'utilise une file d'attente SQS FIFO avec SSE activé. Lorsque j'utilise un client SQS pour appeler getQueueUrl(), une exception est levée avec le message All requests to this queue must use HTTPS and SigV4.Appel de getQueueUrl() sur FIFO Queue avec SSE Enabled Résultats dans 403/Toutes les requêtes dans cette file doivent utiliser HTTPS et SigV4

En utilisant la dernière version du aws-java-sdk:

<dependency> 
     <groupId>com.amazonaws</groupId> 
     <artifactId>aws-java-sdk</artifactId> 
     <version>1.11.160</version> 
    </dependency> 

Le code suivant reproduit le problème:

public class SimpleSqsClient { 

    private static ClientConfiguration clientConfiguration() { 
     ClientConfiguration clientConfiguration = new ClientConfiguration(); 
     clientConfiguration.setProxyHost("proxy.foo.com"); 
     clientConfiguration.setProxyPort(8099); 
     clientConfiguration.setProxyUsername("username"); 
     clientConfiguration.setProxyPassword("password"); 
     clientConfiguration.setProtocol(Protocol.HTTP); 
     clientConfiguration.setPreemptiveBasicProxyAuth(false); 

     return clientConfiguration; 
    } 

    public static void main(String[] args) throws Exception { 

     /* 
     * The ProfileCredentialsProvider will return your [default] credential 
     * profile by reading from the credentials file located at 
     * (~/.aws/credentials). 
     */ 
     AWSCredentials credentials = null; 
     try { 
      credentials = new ProfileCredentialsProvider().getCredentials(); 
     } catch (Exception e) { 
      throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " 
        + "Please make sure that your credentials file is at the correct " 
        + "location (~/.aws/credentials), and is in valid format.", e); 
     } 

     AmazonSQS sqs = AmazonSQSClientBuilder.standard().withClientConfiguration(clientConfiguration()) 
       .withCredentials(new ProfileCredentialsProvider("SOME_PROFILE")) 
       .withRegion(Regions.US_EAST_1).build(); 

     System.out.println("==========================================="); 
     System.out.println("Simple SQS Test"); 
     System.out.println("===========================================\n"); 
     try { 

      System.out.println(sqs.getQueueUrl("some-sse-enabled-queue.fifo")); 

     } catch (AmazonServiceException ase) { 
      System.out.println("Caught an AmazonServiceException, which means your request made it " 
        + "to Amazon SQS, but was rejected with an error response for some reason."); 
      System.out.println("Error Message: " + ase.getMessage()); 
      System.out.println("HTTP Status Code: " + ase.getStatusCode()); 
      System.out.println("AWS Error Code: " + ase.getErrorCode()); 
      System.out.println("Error Type:  " + ase.getErrorType()); 
      System.out.println("Request ID:  " + ase.getRequestId()); 
     } catch (AmazonClientException ace) { 
      System.out.println("Caught an AmazonClientException, which means the client encountered " 
        + "a serious internal problem while trying to communicate with SQS, such as not " 
        + "being able to access the network."); 
      System.out.println("Error Message: " + ace.getMessage()); 
     } 

    } 
} 

sortie:

Caught an AmazonServiceException, which means your request made it to Amazon SQS, but was rejected with an error response for some reason. 
Error Message: All requests to this queue must use HTTPS and SigV4. (Service: AmazonSQS; Status Code: 403; Error Code: InvalidSecurity; Request ID: ...) 
HTTP Status Code: 403 
AWS Error Code: InvalidSecurity 
Error Type:  Client 
Request ID:  ... 

Répondre

0

Modification

clientConfiguration.setProtocol(Protocol.HTTP); 

à

clientConfiguration.setProtocol(Protocol.HTTPS); 

résolu le problème