Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Integration Concepts: Connect MuleSoft With Amazon S3

DZone's Guide to

Integration Concepts: Connect MuleSoft With Amazon S3

Learn to connect Mule to the Amazon Simple Storage Service API, letting you store objects, download and use data with other AWS services and more.

· Integration Zone
Free Resource

The Integration Zone is brought to you in partnership with Cloud Elements.  What’s below the surface of an API integration? Download The Definitive Guide to API Integrations to start building an API strategy.

Image titleThe MuleSoft Amazon S3 connector provides connectivity to Amazon Simple Storage Service API. It provides an interface with S3 to create Buckets, store objects, download and use data with other AWS services. Apps that need internet storage can be built using S3 Connector. 

This article explains how to use the S3 connector to connect with Amazon S3 instance and perform the following actions:

  • Create Bucket
  • Create Object
  • Delete Object
  • Delete Bucket

To use the Amazon S3 connector, you must have access to Amazon Web Services. You can create a free account on Amazon and start using their services.

You can get your access key and secret key credentials by clicking "My Security Credentials." We need these credentials to configure the S3 connector.

Image title

Let's start by developing a flow for creating a Bucket in S3 instance. Put together all of the pallets to create the flow below:

Image title

Once you have all the pallets, configure them. I am using the below config:

HTTP- Port 8091, Path- createBucket, Method- POST

Amazon S3- Click the green plus sign to the right of Connector Configuration and set the fields as shown in the below example.

Image title

Use Test Connection to test the connectivity if Connector is able to connect to Amazon S3 successfully.

Let's provide the bucket name as "myfirstmulebucket" and operation as "Create Bucket." The bucket parameter was defined in the mule-app.properties file.

Image title

Set Payload - #['Mule Bucket Created on S3']

As we have configured the pallets, our app is ready to be deployed and tested. Just run it and deploy it on your Mule Runtime env. 

Hit the Url - http://localhost:8091/createBucket 

The following response will be returned:

Image title

Your bucket is created on AWS. 

Image title

I will show you how will it look when you click on myfirstmulebucket:

Image title

This completes the creation of a bucket on Amazon S3. It was an easy task, wasn't it?

Let's learn how to create an object inside this bucket.

I am using below configs to create an Object in S3:

HTTP- Port 8091, Path- createObject, Method- POST

The bucket name will be same as "myfirstmulebucket" and operation as "Create Object." The bucket parameter has been defined in the mule-app.properties file.

Image title

We can give any value in Key. I am uploading a JSON, so I have used "JsontestObj." The content reference will be what content we want to upload. It will be the same content that I will be providing in my request payload, so Content Reference will be #[payload].

In Set Payload, please use #['Json Message uploaded on'] #{bucket} which you will see as a response once the object is created.

As we have configured all of the pallets, our app is ready to be deployed and tested. Just run it and deploy it on your Mule Runtime env. 

Provide a JSON request in the body and hit the Url - http://localhost:8091/createObject.

The following response will be returned:

Image title

This will create an object in the bucket.

Image title

Just click on the object to see the details for this object.

Image title

To see the content, we can click on the link shown in the above pic and the JSON content will be downloaded to your system.

This completes the demo on creating an object in an S3 Bucket.

The State of API Integration Report provides data from the Cloud Elements platform and will help all developers navigate the recent explosion of APIs and the implications of API integrations to work more efficiently in 2017 and beyond.

Topics:
amazon s3 ,anypoint connector ,mulesoft ,mule ,integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}