Learn how to connect Mule to AWS Simple Storage Service API
The Anypoint Amazon S3 Connector allows developers to connect and access Amazon S3 API. It provides an interface with Amazon S3 to create buckets, store objects, download and use data with other AWS services and build applications that call for internet storage – all from within MuleSoft Anypoint Platform.
What is Amazon S3?
AWS S3 (storage for the Internet) is a cloud base object storage built to store and retrieve any amount of data at any time, from anywhere on the web – web sites and mobile apps, corporate applications, and data from IoT sensors or devices.
This blog post explains how to use Mulesoft AWS S3 Connector to connect to AWS S3 and download a specific object and how to download all objects from a bucket.
Prerequisites
In order to use the AWS S3 connector, you must have the following:
- AWS account
- AWS access key and secret key (credentials in a form of IAM)
- Anypoint Studio Enterprise edition and Mule Anypoint Amazon Connector
Installing and Configuring
- In Anypoint Studio, click Help->Install New Software in the Studio menu.
- Search for the connector and click Install.
- Follow the prompts to install the connector.
Implementation
The Mule Project below is used to download an object from an AWS S3 Bucket using AWS S3 Connector.
Below you can find an explanation of the steps needed for integrating AWS S3 with Mulesoft Application.
- Create a new Anypoint Studio Project and Flow.
- Create a global element for Amazon S3 configuration which can be reused in all other flows across the Mule project
- Configure the Amazon S3 connector by providing the Access Key and Secret Key
- Test the connectivity in order to confirm that the connector is able to connect to AWS S3.
- Drag an HTTP endpoint and create a new HTTP Listener Configuration. The service will be available on the following URL: http://localhost:8081/get-object
- Drag an Amazon S3 connector into the flow and configure it by providing the items written below in order to download the object from Amazon S3 bucket and store locally
- Connector Configuration (Link to the previously created S3 Configuration)
- Operation (Get object content)
- Bucket Name
- Key
- Drag Object To Byte Array Transformer into the flow in order to serialize the object
- Add File Endpoint in order to write file on the local file system
- Drag Set Payload Transformer into the flow in order to set the payload
- Run the Mule Application and trigger the URL via Postman
- Confirm that the file was downloaded locally
The following example explains how to list all objects and how to download all of them.
Conclusion
From the examples, we can see that Amazon S3 connector facilitates easy integration of your Mule application with Amazon S3 API.