title: Generate presigned URL with Quarkus
body: <p>I am facing a problem when I try to generate a presigned url to GET file from AWS S3 with AWS SDK in Quarkus.</p>
  <pre><code>&lt;Error&gt;
      &lt;Code&gt;SignatureDoesNotMatch&lt;/Code&gt;
      &lt;Message&gt;The request signature we calculated does not match the signature you provided. Check your key and signing method.&lt;/Message&gt;
  ....
  </code></pre>
  <p>I get this error when I use inject directly S3Presigner bean (but when I launch test with localstack. It work perfeclty (see test below)).</p>
  <pre><code>@Inject
      S3Presigner s3Presigner;
  ....
  
  public URL generatePresignedUrl(String bucketName, String key, Long duration) {
          
  final var getObjectRequest = GetObjectRequest.builder()
       .bucket(bucketName)
       .key(key)
       .build();
  
  final var getObjectPresignRequest = GetObjectPresignRequest.builder()
       .signatureDuration(Duration.ofSeconds(duration))
       .getObjectRequest(getObjectRequest)
       .build();
  
  final var presignedGetObjectRequest = s3Presigner.presignGetObject(getObjectPresignRequest);
  
       return presignedGetObjectRequest.url();
  </code></pre>
  <p>But when I instantiate S3Presigner with S3Presigner.create(). it work when I try with lambda and disable my integration test because I face another problem (see test below)</p>
  <pre><code>public URL generatePresignedUrl(String bucketName, String key, Long duration) {
      final var getObjectRequest = GetObjectRequest.builder()
          .bucket(bucketName)
          .key(key)
          .build();
      final var getObjectPresignRequest = GetObjectPresignRequest.builder()
          .signatureDuration(Duration.ofSeconds(duration))
          .getObjectRequest(getObjectRequest)
          .build();
  
      try (final var s3Presigner = S3Presigner.create()) {
          final var presignedGetObjectRequest = s3Presigner.presignGetObject(getObjectPresignRequest);
  
          return presignedGetObjectRequest.url();
      } catch (Exception ex) {
          log.errorf(ex, &quot;Error occurred when generating pre-signed url&quot;);
          throw new ServiceException(ErrorType.INTERNAL_SERVER_ERROR);
      }
  }
  </code></pre>
  <p><strong>Test problem:</strong></p>
  <p><strong>In case of injection bean:</strong></p>
  <p>Request 1: Return presigned url with localhost domain like this : <a href="http://127.0.0.1:49399/test-bucket/...." rel="nofollow noreferrer">http://127.0.0.1:49399/test-bucket/....</a>. (test OK, but lambda return signature problem)</p>
  <p>Request 2: I can download file and check content-type.</p>
  <p><strong>In case of instantiating S3Presigner with S3Presigner.create():</strong></p>
  <p>Request 1: Return presigned url with amazonaws.com domain like this : <a href="https://test-bucket.s3.eu-west-1.amazonaws.com/...." rel="nofollow noreferrer">https://test-bucket.s3.eu-west-1.amazonaws.com/....</a>.</p>
  <p>Request 2: KO</p>
  <pre><code>@Test
  @DisplayName(&quot;Should return presigned url from S3&quot;)
  public void should_return_presigned_url() {
      // Request 1: returning presigned url
      String urlRaw = given()
          .contentType(&quot;application/json&quot;)
          .accept(&quot;application/json&quot;)
          .when()
          .get(&quot;/path/presigned-url&quot;)
          .prettyPeek()
          .then()
          .statusCode(200)
          .extract()
          .as(String.class);
  
      final var url = URI.create(urlRaw);
      Map&lt;String, String&gt; collect = Arrays.stream(url.getQuery().split(&quot;&amp;&quot;)).map(s -&gt; s.split(&quot;=&quot;)).collect(Collectors.toMap(e -&gt; e[0], e -&gt; e[1]));
  
      // Request 2: Test to download file uploaded in localstack in init step
      given()
          .baseUri(url.getScheme() + &quot;://&quot; + url.getAuthority())
          .port(url.getPort())
          .queryParams(collect)
          .get(url.getPath())
          .prettyPeek()
          .then()
          .contentType(&quot;application/octet-stream&quot;);
  }
  </code></pre>
  <p><em><strong>build.gradle</strong></em></p>
  <pre><code>dependencies {
      implementation enforcedPlatform(&quot;io.quarkus:quarkus-universe-bom:2.9.2.Final&quot;)
      implementation 'io.quarkus:quarkus-config-yaml'
      implementation 'io.quarkus:quarkus-arc'
      implementation 'com.google.guava:guava'
      implementation 'io.quarkus:quarkus-amazon-lambda-http'
      implementation 'io.quarkus:quarkus-resteasy'
      implementation 'io.quarkus:quarkus-resteasy-jackson'
      implementation &quot;io.quarkus:quarkus-smallrye-openapi&quot;
      implementation 'io.quarkus:quarkus-amazon-s3'
      implementation 'io.quarkus:quarkus-amazon-lambda-xray'
  
      // Cxf
      implementation &quot;org.apache.cxf.xjc-utils:cxf-xjc-runtime:3.3.1&quot;
      implementation &quot;org.apache.commons:commons-lang3:3.12.0&quot;
  
      // Logging
      implementation &quot;org.jboss.logging:commons-logging-jboss-logging:1.0.0.Final&quot;
  
      // AWS
      implementation 'com.amazonaws:aws-xray-recorder-sdk-apache-http:2.11.2'
      implementation 'com.amazonaws:aws-xray-recorder-sdk-aws-sdk-v2-instrumentor:2.11.2'
      implementation 'software.amazon.awssdk:url-connection-client:2.17.229'
      testImplementation 'software.amazon.awssdk:apache-client:2.17.229'
  
      // Mapping dependencies
      implementation &quot;org.mapstruct:mapstruct:1.4.2.Final&quot;
      annotationProcessor &quot;org.mapstruct:mapstruct-processor:1.4.2.Final&quot;
      annotationProcessor &quot;org.projectlombok:lombok-mapstruct-binding:0.2.0&quot;
  
      testImplementation &quot;io.quarkus:quarkus-junit5&quot;
      testImplementation &quot;io.rest-assured:rest-assured&quot;
      testImplementation &quot;org.assertj:assertj-core:3.18.1&quot;
      testImplementation &quot;io.quarkus:quarkus-junit5-mockito&quot;
      testImplementation &quot;org.mockito:mockito-core:3.6.0&quot;
      testImplementation &quot;org.mockito:mockito-junit-jupiter:3.6.0&quot;
      testImplementation &quot;com.github.tomakehurst:wiremock-jre8:2.27.2&quot;
  
      // Test contrainers
      testImplementation platform(&quot;org.testcontainers:testcontainers-bom:1.16.3&quot;)
      testImplementation &quot;org.testcontainers:testcontainers&quot;
      testImplementation &quot;org.testcontainers:junit-jupiter&quot;
      testImplementation &quot;org.testcontainers:localstack&quot;
      // AWS SDK 1.x needed for localstack
      testImplementation(&quot;com.amazonaws:aws-java-sdk-core:1.12.15&quot;) {
          exclude group: &quot;com.amazonaws&quot;, module: &quot;xray&quot;
      }
  }
  </code></pre>
  <p>Do you have any idea please?</p>