Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Amazon RDS Connector

Select

The Anypoint Connector for Amazon RDS provides connectivity to the Amazon Relational Database Service (Amazon RDS) API, enabling you to interface with Amazon RDS to provide cost-efficient and resizable capacity while automating time-consuming administration tasks such as hardware provisioning, database setup, patching and backups.

Prerequisites

To use the Amazon RDS Connector, you must have the following:

  • Access to Amazon Web Services - RDS.

  • To access AWS with the connector, you need AWS Identity and Access Management (IAM) user account credentials.

  • Anypoint Studio version 7.0 (or higher) or Anypoint Design Center.

Compatibility

Amazon RDS connector is compatible with:

Application/Service Version

Mule Runtime

4.0.0

Amazon Java SDK for RDS

v1.11.172

Java

1.8.0_x or higher

Anypoint Studio

7.0 or higher

Install the Connector

  1. In Anypoint Studio, click the Exchange icon in the Studio taskbar.

  2. Click Login in Anypoint Exchange.

  3. Search for the connector and click Install.

  4. Follow the prompts to install the connector.

When Studio has an update, a message displays in the lower right corner, which you can click to install the update.

Configuring the Connector Global Element

To use the Amazon RDS connector in your Mule application, configure a global Amazon RDS element that can be used by all the Amazon RDS connectors in your project.

Configuring With Studio Visual Editor

  1. Click the Global Elements tab at the base of the canvas.

  2. On the Global Configuration Elements screen, click Create. Following window would be displayed.

    Global Configuration Elements Wizard

  3. In the Choose Global Type wizard, expand Connector Configuration and select Amazon RDS Configuration and click Ok. Following window would be displayed.

    Create DB Instance Configure

  4. Configure the parameters according to instructions below.

    Parameter Description

    Name

    A name for the configuration to reference it.

    Region Endpoint

    Region to be used for the Amazon RDS client, when not selected defaults to 'us-east-1'.

    Access Key

    Alphanumeric text string that uniquely identifies the user who owns the account.

    Secret Key

    Key that plays the role of a password.

    Try Default AWS Credentials Provider Chain

    Checkbox that controls whether temporary credentials should be used.

    In the image above, the placeholder values refer to a configuration file mule-artifact.properties placed in the src/main/resources folder of your project. You can either enter your credentials into the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better re-usability of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ.

  5. Keep the Advanced tab which has Reconnection strategy with their default entries.

  6. Click Test Connection to confirm that the parameters of your global configuration are accurate, and that Mule is able to successfully connect to Amazon RDS.

  7. Click OK to save the global connector configurations.

Configuring With the XML Editor or Standalone

Ensure that you have included the Amazon RDS namespaces in your configuration file.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:rds="http://www.mulesoft.org/schema/mule/rds"
        xmlns:http="http://www.mulesoft.org/schema/mule/http"
        xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/rds http://www.mulesoft.org/schema/mule/rds/current/mule-rds.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

<!-- Put your flows and configuration elements here -->

</mule>

Follow these steps to configure an Amazon RDS connector in your application:

Create a global Amazon RDS configuration outside and above your flows, using the following global configuration code.


          
       
1
2
3
<rds:config name="Amazon_RDS_Configuration">
        <rds:basic-connection accessKey="${config.accessKey}" secretKey="${config.secretKey}" region="${config.region}"/>
</rds:config>

If you or your IAM users forget or lose the secret access key, you can create a new access key.

RDS Connector Operations

The Amazon RDS connector supports the following list of operations:

DB Instances

  • CreateDBInstance

  • CreateDBInstanceReadReplica

  • DeleteDBInstance

  • DescribeDBInstances

  • ModifyDBInstance

  • RebootDBInstance

  • RestoreDBInstanceFromDBSnapshot

  • RestoreDBInstanceToPointInTime

  • StartDBInstance

  • StopDBInstance

DB Snapshots

  • CreateDBSnapshot

  • DeleteDBSnapshot

  • DescribeDBSnapshots

  • ModifyDBSnapshot

Events

  • DescribeEvents

Reserved DB Instances

  • DescribeReservedDBInstances

  • DescribeReservedDBInstancesOfferings

  • PurchaseReservedDBInstancesOffering

Using the Connector

Amazon RDS connector is an operation-based connector, which means that when you add the connector to your flow, you need to configure a specific web service operation for the connector to perform. Amazon RDS connector v1.0.0 supports 18 operations.

Connector Namespace and Schema

When designing your application in Studio, the act of dragging the connector operation from the palette onto the Anypoint Studio canvas should automatically populate the XML code with the connector namespace and schema location.

Namespace: http://www.mulesoft.org/schema/mule/rds

Schema Location: http://www.mulesoft.org/schema/mule/rds/current/mule-rds.xsd

If you are manually coding the Mule application in the Studio XML editor or other text editor, paste the namespace and schema location into the header of your Configuration XML, inside the <mule> tag.


         
      
1
2
3
4
5
6
7
8
9
10
<mule xmlns:rds="http://www.mulesoft.org/schema/mule/rds" xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/rds http://www.mulesoft.org/schema/mule/rds/current/mule-rds.xsd">

      <!-- here it goes your global configuration elements and flows -->

</mule>

Using the Connector in a Mule App in Anypoint Studio 7.0 or higher

If you are developing a Mule application in Anypoint Studio 7.0 or higher, this XML snippet must be included in your pom.xml file.


         
      
1
2
3
4
5
6
<dependency>
    <groupId>org.mule.connectors</groupId>
    <artifactId>mule-rds-connector-4.x</artifactId>
    <version>1.0.0</version>
    <classifier>mule-plugin</classifier>
</dependency>

Use Cases and Demos

Listed below are the few common use cases for the connector:

Use Case Description

Creating a DB instance

By using Amazon RDS, a DB instance of our choice can be created over all the Amazon supported Databases.

Stopping a DB instance

By using Amazon RDS, a DB instance which is in available or running state can be stopped.

Starting a DB instance

By using Amazon RDS, a DB instance which is in stopped state can be started.

Retrieve DB instances

By using Amazon RDS, information of all the available list of DB instances or any specific one we want can be retrieved.

Creating a DB snapshot

By using Amazon RDS, a DB snapshot for a DB instance can be created.

Retrieve DB snapshots

By using Amazon RDS, information of all the available list of DB snapshots or any specific one we want can be retrieved.

Deleting a DB snapshot

By using Amazon RDS, a DB snapshot can be deleted.

Demo Mule Application Using the Connector

This demo Mule application creates a DB instance.

Creating a DB instance

  1. Create a new Mule Project in Anypoint Studio.

  2. Add the following properties to the mule-artifact.properties file to hold your Amazon RDS credentials and place it in the project’s src/main/resources directory.

    
                 
              
    1
    2
    3
    
    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    config.region=<Region>
  3. Drag an HTTP Listener operation onto the canvas and configure the following parameters:

    rds http config props

    Parameter Value

    Display Name

    Listener

    Extension Configuration

    If no HTTP element has been created yet, click the plus sign to add a new HTTP Listener Configuration and click OK (leave the values to its defaults).

    Path

    /create-db-instance

  4. Drag a Transform Message component after the HTTP connector which would retrieve the http query parameters and set to the payload. Then click the component to open its properties editor. The DataWeave script should look similar to the following:

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    %dw 2.0
    output application/java
    ---
    {
            dbInstanceClass : attributes.queryParams.dbInstanceClass,
            dbInstanceIdentifier : attributes.queryParams.dbInstanceIdentifier,
            engine : attributes.queryParams.engine,
            allocatedStorage : attributes.queryParams.allocatedStorage,
            masterUsername : attributes.queryParams.masterUsername,
            masterUserPassword : attributes.queryParams.masterUserPassword
    }
  5. Add a Logger component after the Transform Message component to print the payload data that was set in the previous processor to the Mule Console. Configure the Logger according to the table below.

    Parameter Value

    Display Name

    Logger (or any other name you prefer)

    Message

    #[payload]

    Level

    INFO

  6. Drag the Amazon RDS Connector next to the Logger component.

  7. Configure the RDS connector by adding a new Amazon RDS Global Element. Click the plus sign next to the Extension Configuration field.

    1. Configure the global element according to the table below:

      Parameter Description Value

      Name

      Enter a name for the configuration to reference it.

      <Configuration_Name>

      Region Endpoint

      Region to be set for the Amazon RDS Client.

      When not selected from the drop down list, it defaults to 'us-east-1'

      Access Key

      Alphanumeric text string that uniquely identifies the user who owns the account.

      ${config.accesskey}

      Secret Key

      Key that plays the role of a password.

      ${config.secretkey}

    2. Your configuration should look like this:

      rds use case config

    3. The corresponding XML configuration should be as follows:

      <rds:config name="Amazon_RDS_Configuration">
          <rds:basic-connection accessKey="${config.accessKey}" secretKey="${config.secretKey}"/>
      </rds:config>
  8. Click Test Connection to confirm that Mule can connect with the Amazon RDS instance. If the connection is successful, click OK to save the configurations. Otherwise, review or correct any incorrect parameters, then test again.

  9. Back in the properties editor of the Amazon RDS connector, configure the parameters for the createDbInstance operation:

    Parameter Value

    General

    Display Name

    Create DB instance (or any other name you prefer)

    Extension Configuration

    Amazon_RDS_Configuration (the reference name to the global element you have created).

    Db instance class

    #[payload.dbInstanceClass]

    Db instance identifier

    Any valid identifier to uniquely identify the DB instance.

    Engine

    Choose among the 6 DB engines that Amazon RDS supports.

    Security

    Master username

    Any valid user name for the Database

    Master user password

    Password for the Database user

    Storage and Maintenance

    Allocated storage

    A number representing the storage in GB.

    create db instance parameter props

  10. Check that your XML looks like this:

    <rds:create-db-instance config-ref="Amazon_RDS_Configuration" dbInstanceClass="#[payload.dbInstanceClass]"
                    dbInstanceIdentifier="#[payload.dbInstanceIdentifier]" engine="#[payload.engine]" allocatedStorage="#[payload.allocatedStorage]"
                    doc:name="Create db instance" masterUsername="#[payload.masterUsername]" masterUserPassword="#[payload.masterUserPassword]"/>
  11. Add a Logger component after the RDS connector to print the payload data that was outputted from the Create DB instance processor to the Mule Console. Configure the Logger according to the table below.

    Parameter Value

    Display Name

    Logger (or any other name you prefer)

    Message

    #[payload]

    Level

    INFO

  12. Drag a Transform Message component after the Logger component which would set the payload that would be transferred to the browser. Then click the component to open its properties editor. The DataWeave script should look similar to the following:

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    
    %dw 2.0
    output application/json
    ---
    {
        success: true,
        info: payload
    }
  13. Save and Run the project as a Mule Application. Right-click the project in Package Explorer and click Run As > Mule Application.

  14. Open a browser and check the response after entering the URL http://localhost:8081/create-db-instance. You should see the generated DB instance ID in the browser and its information in the console.

Demo Mule Application XML Code

Paste this code into your XML Editor to quickly load the flow for this example use case into your Mule application.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:rds="http://www.mulesoft.org/schema/mule/rds"
        xmlns:http="http://www.mulesoft.org/schema/mule/http"
        xmlns="http://www.mulesoft.org/schema/mule/core"
        xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/rds http://www.mulesoft.org/schema/mule/rds/current/mule-rds.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

        <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
                <http:listener-connection host="127.0.0.1" port="8081" />
        </http:listener-config>

        <rds:config name="Amazon_RDS_Configuration" doc:name="Amazon RDS Configuration">
                <rds:basic-connection accessKey="${config.accessKey}" secretKey="${config.secretKey}" />
        </rds:config>

        <flow name="create-db-instance-flow">
                <http:listener config-ref="HTTP_Listener_config" path="/create-db-instance" doc:name="Listener"/>
                <ee:transform doc:name="Transform Message">
                        <ee:message >
                                <ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
        dbInstanceClass : attributes.queryParams.dbInstanceClass,
        dbInstanceIdentifier : attributes.queryParams.dbInstanceIdentifier,
        engine : attributes.queryParams.engine,
        allocatedStorage : attributes.queryParams.allocatedStorage,
        masterUsername : attributes.queryParams.masterUsername,
        masterUserPassword : attributes.queryParams.masterUserPassword
}]]></ee:set-payload>
                        </ee:message>
                </ee:transform>

                <logger level="INFO" doc:name="Logger" message="#[payload]"/>
                <rds:create-db-instance config-ref="Amazon_RDS_Configuration" dbInstanceClass="#[payload.dbInstanceClass]"
                dbInstanceIdentifier="#[payload.dbInstanceIdentifier]" engine="#[payload.engine]" allocatedStorage="#[payload.allocatedStorage]"
                doc:name="Create db instance"
                 masterUsername="#[payload.masterUsername]" masterUserPassword="#[payload.masterUserPassword]"/>

                 <logger level="INFO" doc:name="Logger" message="#[payload]"/>

                <ee:transform doc:name="Transform Message">
                        <ee:message >
                                <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
        success: true,
    info: payload
}]]></ee:set-payload>
                        </ee:message>
                </ee:transform>

        </flow>

</mule>

See Also