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.
Join the DZone community and get the full member experience.
Join For FreeThe 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.
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:
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.
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.
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:
Your bucket is created on AWS.
I will show you how will it look when you click on myfirstmulebucket:
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.
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:
This will create an object in the bucket.
Just click on the object to see the details for this object.
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.
Opinions expressed by DZone contributors are their own.
Comments