<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eric Rosetti Lessa</title>
    <description>The latest articles on DEV Community by Eric Rosetti Lessa (@ericrlessa).</description>
    <link>https://dev.to/ericrlessa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1192238%2F80ef6c9b-7450-4159-b93e-a610098da1da.jpeg</url>
      <title>DEV Community: Eric Rosetti Lessa</title>
      <link>https://dev.to/ericrlessa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ericrlessa"/>
    <language>en</language>
    <item>
      <title>Effective Testing of Cloud Components with Quarkus and LocalStack</title>
      <dc:creator>Eric Rosetti Lessa</dc:creator>
      <pubDate>Fri, 08 Mar 2024 15:03:02 +0000</pubDate>
      <link>https://dev.to/ericrlessa/effective-testing-of-cloud-components-with-quarkus-and-localstack-3be7</link>
      <guid>https://dev.to/ericrlessa/effective-testing-of-cloud-components-with-quarkus-and-localstack-3be7</guid>
      <description>&lt;p&gt;In this tutorial, we’ll understand how to code and test applications that need to store data, such as images and documents, on &lt;a href="https://aws.amazon.com/s3/" rel="noopener noreferrer"&gt;Amazon S3&lt;/a&gt; and similar cloud services.  We’ll build a Java application to integrate with the S3 API and use &lt;a href="https://quarkus.io/" rel="noopener noreferrer"&gt;Quarkus&lt;/a&gt; for testing with containers. In the end, we’ll deploy the entire application stack to &lt;a href="https://aws.amazon.com/" rel="noopener noreferrer"&gt;Amazon Web Services&lt;/a&gt; and see it live. Our goal is to practice and learn how easy it can be to code using local tests with TestContainers.&lt;/p&gt;

&lt;p&gt;You can find all the code in the following repository:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ericrlessa/s3-quarkus-sample" rel="noopener noreferrer"&gt;https://github.com/ericrlessa/s3-quarkus-sample&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This sample project shows 3 Rest services to put, get, and generate a pre-signed URL for an image stored in S3. In the project, there are separate test classes for each type of integration using the “REST Assured” library and test containers. Also, there is an &lt;a href="https://aws.amazon.com/cloudformation/" rel="noopener noreferrer"&gt;Amazon CloudFormation&lt;/a&gt; template to deploy the stack to your AWS account.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First of all, the S3 quarkiverse extension should be added to the project. If you don’t have a quarkus project yet, or the &lt;a href="https://quarkus.io/guides/cli-tooling" rel="noopener noreferrer"&gt;Quarkus CLI&lt;/a&gt; installed, check the “&lt;a href="https://quarkus.io/get-started/" rel="noopener noreferrer"&gt;Getting Started&lt;/a&gt;” guide and come back. The S3 extension can be added with this command, in your project directory:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ quarkus ext add io.quarkiverse.amazonservices:quarkus-amazon-s3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As a result, the following dependencies are added to the project:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  &amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;${quarkus.platform.group-id}&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;quarkus-amazon-services-bom&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;${quarkus.platform.version}&amp;lt;/version&amp;gt;
    &amp;lt;type&amp;gt;pom&amp;lt;/type&amp;gt;
    &amp;lt;scope&amp;gt;import&amp;lt;/scope&amp;gt;
 &amp;lt;/dependency&amp;gt;

 &amp;lt;dependency&amp;gt;
     &amp;lt;groupId&amp;gt;io.quarkiverse.amazonservices&amp;lt;/groupId&amp;gt;
     &amp;lt;artifactId&amp;gt;quarkus-amazon-s3&amp;lt;/artifactId&amp;gt;
 &amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
      You also need to add one HTTP client library as a dependency, let’s use url-connection-client.

     ```


      &amp;lt;dependency&amp;gt;
         &amp;lt;groupId&amp;gt;software.amazon.awssdk&amp;lt;/groupId&amp;gt;
         &amp;lt;artifactId&amp;gt;url-connection-client&amp;lt;/artifactId&amp;gt;
      &amp;lt;/dependency&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Docker containers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you build the sample project with the above dependencies, with the &lt;code&gt;$ quarkus build&lt;/code&gt; command, you can observe that the necessary containers are started automatically.&lt;/p&gt;

&lt;p&gt;Let’s start the quarkus in dev mode with the following command: &lt;code&gt;$ quarkus dev&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then, open a new terminal and verify the containers running with &lt;code&gt;$ docker ps&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9jeznukgn1ox2ys51xpt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9jeznukgn1ox2ys51xpt.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Three containers should be running:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;localstack/localstack -&amp;gt; LocalStack is a service emulator that lets you test cloud applications locally, without incurring in network and service costs. Also it enables applications to test cloud clientes and APIs in Continuous Integration pipelines. Learn more at &lt;a href="https://docs.localstack.cloud/getting-started/" rel="noopener noreferrer"&gt;https://docs.localstack.cloud/getting-started/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;mariadb -&amp;gt; Container running a mariadb database. We will use to store some metadata and a reference to S3 objects.&lt;/p&gt;

&lt;p&gt;testcontainers/ryuk -&amp;gt; Testcontainers is an open source framework for providing throwaway, lightweight instances of databases, message brokers, web browsers, or just about anything that can run in a Docker container.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is no explicit dependency for testcontainers and localstack. We only need to add the extensions for S3 and MariaDB. With those dependencies present, quarkus automatically initializes a local environment during test and dev mode. In dev mode, the containers are started up without any configuration. In test mode, when you use @QuarkusTest annotation in your class test, you tell Quarkus to prepare the local environment before starting the tests. Everything is integrated without configuring one single property in the application. Learn more about other &lt;a href="https://quarkus.io/guides/dev-services" rel="noopener noreferrer"&gt;DevServices&lt;/a&gt; in the quarkus documentation.&lt;/p&gt;

&lt;p&gt;But what if we want to avoid the localstack running by quarkus? What can be done if you want to run the S3 localcontainer separately? You can override the localcontainer host using an application property:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ quarkus.s3.endpoint-override=http://localhost:4566&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let’s configure this property to verify it’s effect. In the sample project, from the github repository, open the file “application-dev.properties” file, under “src/main/resources”, and uncomment the line with this property. After this, enter in “quarkus dev” mode and run “docker ps” in another terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff6sm5r80x5w7p1ma2jon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff6sm5r80x5w7p1ma2jon.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where is the localstack container? Quarkus did not start the localstack because you explicitly set the host, saying that you would take care of this by yourself. You could, for example, run your localstack directly by a docker command instead of quarkus:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ docker run -it --publish 4566:4566 -e SERVICES=s3 -e START_WEB=0 localstack/localstack:3.0.1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Remember that this is only necessary to run localstack with extensive configuration. You can use the default DevService just as well. This demonstrates the two alternatives to deal with AWS local environment, with and without quarkus devservices.&lt;/p&gt;

&lt;p&gt;To see the impact in tests, do the same thing in the application.properties located in the src/test/resources folder of the test project. Uncomment the line with “quarkus.s3.endpoint-override”, and try to run the test or build the project with “$ quarkus build”. You will receive an error where the stack trace shows the problem:&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

  SdkClientException: Unable to execute HTTP request
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
     You just received a connection error because quarkus did not run a localstack container before running your tests. Let’s fix that with a S3 integration.

3. **Java implementation S3 integration**

     Now that we understand the environment of our AWS S3 local integration, we can go to the Java code. How quarkinverse extension helps coding and S3 integration?
With this extension, you can use the @Inject annotation from jakarta CDI, to get a S3 client and do whatever you want with your bucket, either in production or test code:


     ```java


       @Inject
       private S3Client s3;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; To isolate the interaction with external aws library, I created one interface to abstract this process:

 ```java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   public interface ImageDataRepository {
      public void save(Path file,
                     Image image);
      public byte [] find(Image image);
      public void delete(Image image);
      public String createPresignedGetUrl(Image image);       
      public String getBucketName();
   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
     And the S3Client is injected into a concrete class called S3BucketImage, that invokes the API services.

     To make transfers to S3 safer, we can use pre-signed urls. Those are temporary addresses that lets your application securely share a link with clients and transfer content directly to them.
In our application, there are three rest services (JAX-RS resources) where it is possible to save, get and generate a presigned URL to your S3 object:

     ```java


        @Path("/image")
        public class ImageResource {
           @Inject
           private ImageDataRepository imageDataRepository;

           @POST
           @Consumes(MediaType.MULTIPART_FORM_DATA)
           @Transactional
           public void saveImage(ImageFormData imageFormData){
                Image image = ImageBuilder.newInstance()                                 .withBucket(imageDataRepository.getBucketName())
               .withFileName(imageFormData.fileName)
               .withMimeType(imageFormData.mimeType)
               .addTag("fileName",  imageFormData.fileName).build();
               image.persist();
           imageDataRepository.save(imageFormData.file.toPath(), image);
           }

           @Path("/{id}")
           @GET
           @Produces(MediaType.APPLICATION_OCTET_STREAM)
           public byte[] getImage(@PathParam("id") Long id){
              return imageDataRepository.find(Image.findById(id));
           }

           @Path("/{id}/presignedGetUrl")
           @GET
           public String createPresignedGetUrl(@PathParam("id") Long id){
              return imageDataRepository.createPresignedGetUrl(Image.findById(id));
           }
         } 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; The ImageDataRepository implementation provides the S3 operations:

 ```java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    @ApplicationScoped
    public class S3BucketImage implements ImageDataRepository {
      @ConfigProperty(name = "bucket.name")
      private String bucketName;
      @ConfigProperty(name = "presigned.url.duration.in.minutes")
      private Integer presignedUrlDurationInMinutes;
      @Inject
      private S3Client s3;
      @Inject
      private S3Presigner presigner;

      public String getBucketName(){
         return this.bucketName;
      }

      public void save(Path file,
                Image productImage) {
         List&amp;lt;Tag&amp;gt; tagsS3 = getTags(productImage);
         s3.putObject(
         PutObjectRequest.builder()
           .bucket(productImage.bucket())
           .key(productImage.key())
           .contentType(productImage.mimeType())
          .tagging(Tagging.builder().tagSet(tagsS3).build())
           .build(),
           RequestBody.fromFile(file));
      }

      public void delete(Image productImage) {
           DeleteObjectRequest deleteRequest = DeleteObjectRequest.builder()
           .bucket(productImage.bucket())
           .key(productImage.key())
           .build();

           s3.deleteObject(deleteRequest);
      }

      public byte[] find(Image productImage) {
         try {
             return s3.getObject(GetObjectRequest.builder()
                  .bucket(productImage.bucket())
                  .key(productImage.key())
                  .build()).readAllBytes();
          } catch (IOException e) {
               throw new RuntimeException(e);
          }
      }

      public String createPresignedGetUrl(Image productImage) {
          GetObjectRequest objectRequest = GetObjectRequest.builder()
           .bucket(productImage.bucket())
           .key(productImage.key())
           .build();

          GetObjectPresignRequest presignRequest =  GetObjectPresignRequest.builder()
         .signatureDuration(Duration.ofMinutes(presignedUrlDurationInMinutes))
           .getObjectRequest(objectRequest)
           .build();

          PresignedGetObjectRequest presignedRequest = presigner.presignGetObject(presignRequest);


          return presignedRequest.url().toExternalForm();
      }

      private List&amp;lt;Tag&amp;gt; getTags(Image productImage) {
          List&amp;lt;Tag&amp;gt; tagsS3 = productImage.tags().stream().map(
           t -&amp;gt; parseTagS3(t)
           ).collect(Collectors.toList());
             return tagsS3;
      }

      private Tag parseTagS3(s3sample.domain.Tag t) {
          return Tag.builder().key(t.key()).value(t.value()).build();
      }

      @PostConstruct
      private void createBucket() {
          try {
             try {
                 HeadBucketRequest headBucketRequest = HeadBucketRequest.builder()
                   .bucket(bucketName)
                   .build();
           s3.headBucket(headBucketRequest);
           } catch (NoSuchBucketException e) {
                CreateBucketRequest bucketRequest = CreateBucketRequest.builder()
                   .bucket(bucketName)
                   .build();
                s3.createBucket(bucketRequest);
           }
         } catch (Exception e) {
            //FIXME add log
         }
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
     Notice that the method createBucket() creates the bucket only if does not already exists.

4. **Tests**

     The tests were created using REST Assured to POST and GET the image, and to GET a  pre-signed URL to the image. The tests were separated into two classes, one for get operations, and another to save the image.

     ```java


        @QuarkusTest
        public class ImageGetTest extends ImageTest {
             Image productImage;

             @BeforeEach
             @Transactional
             void startProductFixture(){
                  productImage = ImageBuilder.newInstance()
                    .withFileName(fileName)
                    .withBucket(bucketName)
                    .withMimeType(mimetype)
                    .addTag("fileName", fileName)
                    .addTag("city", "Vitoria")
                    .addTag("country", "Brasil")
                    .build();
                  productImage.persist();
                  imageDataRepository.save(file, productImage);
             }

             @Test
             public void testGetS3ProductImage() {
                    byte [] file = given()
                      .when()
                      .get("/api/image/" + productImage.id)
                      .then()
                      .statusCode(HttpStatus.SC_OK)
                      .extract()
                      .body()
                      .asByteArray(); // Adjust the expected     status code as needed
                    assertThat(file, notNullValue());

                   //saveFileLocalToVerifyManually(file);
             }

             @Test
             public void testPresignedGetUrlS3() {
                  String preAssignedUrl = given()
                     .when()
                     .get("/api/image/%d/presignedGetUrl".formatted(productImage.id))
                     .then()
                     .statusCode(HttpStatus.SC_OK)
                     .extract()
                     .body()
                     .asString();

                  byte [] file = given()
                     .baseUri(preAssignedUrl)
                     .get()
                     .then()
                     .statusCode(HttpStatus.SC_OK)
                     .extract()
                     .body()
                     .asByteArray();

                 assertThat(file, notNullValue());

                //   saveFileLocalToVerifyManually(file);
            }


            private void saveFileLocalToVerifyManually(byte [] file){
                String localFilePath = "/tmp/test.jpg";

                try (FileOutputStream fos = new  FileOutputStream(localFilePath)) {
                    fos.write(file);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

          }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Test to upload the image to S3:

 ```java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     @QuarkusTest
     public class ImagePostTest extends ImageTest {
         @Test
         public void testUpdateS3ProductImage() {
              Integer id = given()
              .multiPart("file", file)
              .multiPart("fileName", fileName)
              .multiPart("mimeType", mimetype)
              .when()
              .post("/api/image")
              .then()
              .statusCode(HttpStatus.SC_OK)
              .extract().path("id");

              Image img = Image.findById(id);
              assertThat(img, notNullValue());
              assertThat(img.bucket(), equalTo(bucketName));
              assertThat(img.id, notNullValue());
              assertThat(img.fileName(), equalTo(fileName));
              assertThat(img.mimeType(), equalTo(mimetype));

              byte [] imageFileData = imageDataRepository.find(img);
              assertThat(imageFileData, notNullValue());

              imageDataRepository.delete(img);
         }
     }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
     The abstract superclass supply common resources to the tests:

     ```Java


        public abstract class ImageTest {
             String fileName = "Vitoria_ES_Brasil.jpg";
             String mimetype = "image/jpeg";
             Path file = Paths.get("src/test/resources/s3sample/domain/core/product/" + fileName);
             @ConfigProperty(name = "bucket.name")
             String bucketName;
             @Inject
             ImageDataRepository imageDataRepository;
        }


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; As you can see, the interface ImageDataRepository provides the implementation to operate on S3. In the end, quarkus will inject an S3Client pointing to the local services running in a docker container.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deploy Cloud formation stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;: The following steps use AWS services that might incur in costs. There is no cost for opening an AWS account and there is a free tier for most services in the first year. You can open your AWS account at &lt;a href="https://aws.amazon.com/free" rel="noopener noreferrer"&gt;https://aws.amazon.com/free&lt;/a&gt;. Remember to delete all resources after finishing this tutorial to avoid unnecessary charges.&lt;/p&gt;

&lt;p&gt;After coding and testing everything locally, it is time to deploy the lambda function in the AWS environment. To deploy the stack, let’s use &lt;a href="https://aws.amazon.com/serverless/sam/" rel="noopener noreferrer"&gt;AWS Serverless Application Model&lt;/a&gt; (SAM):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sam deploy --stack-name cfn-fn --template-file infrastructure.cfn.yaml --resolve-s3 --capabilities "CAPABILITY_IAM" "CAPABILITY_AUTO_EXPAND" "CAPABILITY_NAMED_IAM"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;SAM will create the resources through a CloudFormation Stack that can be observed in service console. For the purposes of this demonstration, the relevant resources are the lambda function with the execution role and their policies, allowing access to the S3 bucket. &lt;/p&gt;

&lt;p&gt;After the deployment, it is possible to use Postman or any other tool to execute the http requests to get and post the image from the Bucket.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  1. Copy the Service HTTP URI generated in the outputs of the recently created stack.
  2. Define the request body:
        - file: binary data 
        - fileName: example.jpg
        - mimeType: image/jpeg
  3. Send the request to Http Api URL, running in AWS.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In Postman, you can use a POST request body of type “form-data” to send your file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3v8zz2agmbd4zr0eylb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx3v8zz2agmbd4zr0eylb.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the file, just change the host of your API Gateway and make a GET request on browser, curl, postman, or any tool of your preference:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://e5fasnm3ak.execute-api.us-east-1.amazonaws.com/api/image/1" rel="noopener noreferrer"&gt;https://e5fasnm3ak.execute-api.us-east-1.amazonaws.com/api/image/1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the pre-signed URL, just adjust the URI:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://e5fasnm3ak.execute-api.us-east-1.amazonaws.com/api/image/1/presignedGetUrl" rel="noopener noreferrer"&gt;https://e5fasnm3ak.execute-api.us-east-1.amazonaws.com/api/image/1/presignedGetUrl&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The server will return the pre-signed URL. Just copy and paste on the browser to see the image.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Delete the stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before deleting the stack, empty the Image Bucket and delete it. After that, you can run the following command or delete the stack on the cloudformation console:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ aws cloudformation delete-stack --stack-name cfn-fn&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Confirm the stack has been deleted&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this article, we demonstrated how applications can use and test object storage, and other cloud services, with Quarkus and TestContainers. That helps applications to be more reliable, without resorting to “mocks” in testing. Containers make it more productive to reproduce and test scenarios and improve the overall developer experience. &lt;/p&gt;

&lt;p&gt;You can put those techniques to practice and learn more in our open-source project &lt;a href="https://github.com/CaravanaCloud/ecomarkets" rel="noopener noreferrer"&gt;EcoMarkets&lt;/a&gt;. Also, you’ll be helping many families to live more sustainably and eat more healthly. Join the project repository activity at &lt;a href="https://github.com/CaravanaCloud/ecomarkets" rel="noopener noreferrer"&gt;https://github.com/CaravanaCloud/ecomarkets&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Quarkus extension for amazon S3:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://quarkus.io/extensions/io.quarkiverse.amazonservices/quarkus-amazon-s3/" rel="noopener noreferrer"&gt;https://quarkus.io/extensions/io.quarkiverse.amazonservices/quarkus-amazon-s3/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quarkiverse doc:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-s3.html" rel="noopener noreferrer"&gt;https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-s3.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Localstack:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.localstack.cloud/getting-started/" rel="noopener noreferrer"&gt;https://docs.localstack.cloud/getting-started/&lt;/a&gt;&lt;br&gt;
Testcontainers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://testcontainers.com/" rel="noopener noreferrer"&gt;https://testcontainers.com/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>quarkus</category>
      <category>test</category>
      <category>aws</category>
      <category>java</category>
    </item>
  </channel>
</rss>
