Download all Objects from an Amazon S3 Bucket using MuleSoft

Here’s a quick example on how you can download all the Objects from an Amazon S3 Bucket using the Amazon S3 Connector.  You can see the flow and the corresponding code (minus the HTTP and Amazon S3 Configuration) below.

Mule Flow Screenshot
Flow to download all files from an S3 Bucket

Some prerequisites before you begin. You’ll need the following:

Let me highlight some of the key areas in the code.

  • When you run the project, you’ll kick off the process by navigating to http://localhost:8081/bucket. This is set in the HTTP Listener.
  • If you’ve pasted my code above into your project, you’ll need to configure the Amazon S3 configuration and the HTTP configuration
  • For the S3 Connector, you’ll need your Amazon AWS Access Key and Secret Key when you set up the configuration. Be sure to click on Test Connection before hitting OK.

    Amazon S3 Global Configuration
    Amazon S3 Global Configuration
  • The first Amazon S3 Connector grabs a list of all the Objects with in a Bucket. The field Bucket Name is hard-coded. You can change this to be dynamic and use a message.inboundProperties value instead.
  • You’ll need to open the properties for the File Connector and set the Path to a local directory before running the project.

With this example, you can see how easy it is to integrate with Amazon S3 without having to write any custom code. The connector provides a wrapper around the Amazon SDK to allow you the ability easily click-and-configure a project.

Document object to String object (Java Code)

Converting a Document object to a String object in Java is an issue I’ve run into a couple times at work. I wanted to see the output of a WebService call response that was in XML in the console. Here’s a quick code snippet I found that handles this: