Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Amazon DynamoDB Connector

Select

Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability.

The Anypoint Connector for Amazon DynamoDB provides connectivity to the Amazon DynamoDB API, enabling you to interact with Amazon DynamoDB to create a database table that can store and retrieve any amount of data, serve any level of request traffic, and automatically spread the data and traffic for the table over a sufficient number of servers to handle the request capacity and the amount of data stored, while maintaining consistent and fast performance.

Prerequisites

This document assumes that you are familiar with Amazon DynamoDB API, Mule, Anypoint Connectors, Anypoint Studio, Mule concepts, elements in a Mule flow, and Global Elements.

For hardware and software requirements and compatibility information, see the Connector Release Notes.

To use this connector with Maven, view the pom.xml dependency information in the Dependency Snippets in Anypoint Exchange.

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

  • Access to Amazon Web Services - DynamoDB.

  • 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 Mozart Flow Designer.

What’s New in this Connector

Support for Mule 4.

To Connect in Anypoint Studio 7

You can use this connector in Anypoint Studio by first downloading it from Exchange and configuring it as needed.

To Install Connector in Studio

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

  2. Click Login in Anypoint Exchange.

  3. Search for this connector and click Install.

  4. Follow the prompts to install this connector.

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

To Configure in Studio

  1. Add a dependency to your file pom.xml.

    
                 
              
    1
    2
    3
    4
    5
    6
    
    <dependency>
      <groupId>org.mule.connectors</groupId>
      <artifactId>mule-dynamodb-connector-4.x</artifactId>
      <version>1.0.0</version>
      <classifier>mule-plugin</classifier>
    </dependency>
  2. Click the Global Elements tab at the base of the canvas.

  3. In the Global Mule Configuration Elements screen, click Create.

  4. In the Choose Global Type wizard, expand Connector Configuration and select Amazon DynamoDB: Configuration and click OK.

    Global Element Configuration Wizard

  5. Configure the parameters according to instructions below.

    Parameter Description

    Name

    Enter a name for the configuration to reference it.

    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 reuse 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.

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

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

  8. Click OK to save the global connector configurations.

  9. Your configuration should look like this:

    DynamoDB use case configuration

Use Case: Studio

This use case provides a Mule flow to create a table in Amazon DynamoDB.

Creating a table in Amazon DynamoDB

  1. Create a new Mule Project in Anypoint Studio.

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

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

    DynamoDB HTTP configuration properties

    Parameter Value

    Display Name

    Listener

    Extension Configuration

    If a HTTP Listener configuration has not been created, click the plus sign to add a new HTTP Listener Configuration and click OK (use localhost for the Host and 8081 for the Port).

    Path

    /createtable

  4. Drag the Amazon DynamoDB Connector Create Table next to the HTTP Listener component.

  5. Configure the DynamoDB connector by adding a new Amazon DynamoDB Global Element. Click the plus sign next to the Connector Configuration field.

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

    Parameter Description Value

    Name

    Enter a name for the configuration to reference it.

    <Configuration_Name>

    Access Key

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

    ${amazon.accesskey}

    Secret Key

    Key that plays the role of a password.

    ${amazon.secretkey}

    Region Endpoint

    Region to be select from drop down for the Amazon DynamoDB Client.

    By default USEAST1

    Your configuration should look like this:

    DynamoDB use case configuration

    The corresponding XML configuration should be as follows:

    
                
             
    1
    2
    3
    
    <dynamodb:config name="Amazon_DynamoDB_Configuration1" doc:name="Amazon DynamoDB Configuration" >
      <dynamodb:basic-connection accessKey="${config.accesskey}" secretKey="${config.secretkey}" />
    </dynamodb:config>
  7. Click Test Connection to confirm that Mule can connect with the DynamoDB instance. If the connection is successful, click OK to save the configurations. Otherwise, review or correct any incorrect parameters, then test again.

  8. In the properties editor of the Amazon DynamoDB Create Table operation, configure the remaining parameters:

    Parameter Value

    Display Name

    Create Table or any other name you prefer.

    Basic Settings

    Extension Configuration

    Amazon_DynamoDB_Configuration - the reference name to the global element you have created).

    General

    TableName

    Any name that you prefer to create your own table

    AttributeDefinitions

    An array of attributes that describe the key schema for the table and indexes.

    KeySchema

    Specifies the attributes that make up the primary key for a table or an index.

    ReadCapacityUnits

    5 - The maximum number of strongly consistent reads per second.

    Write Capacity Units

    5 - The maximum number of writes consumed per second.

    Publish message connector properties

  9. Check that your XML looks like this:

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    <flow name="create-table-flow">
            <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/createtable"/>
            <dynamodb:create-table doc:name="Create table"
              config-ref="Amazon_DynamoDB_Configuration"
              tableName="StudentData"
              readCapacityUnits="5"
              writeCapacityUnits="5">
                    <dynamodb:attribute-definitions >
                            <dynamodb:attribute-definition attributeName="studentId" attributeType="N" />
                    </dynamodb:attribute-definitions>
                    <dynamodb:key-schemas>
                            <dynamodb:key-schema-element attributeName="studentId" keyType="HASH" />
                    </dynamodb:key-schemas>
            </dynamodb:create-table>
        <logger level="INFO" doc:name="Logger" message="#[payload]"/>
    </flow>
  10. Add a Logger component after the Amazon DynamoDB Create Table operation to print the response that is generated by the Create Table operation in 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

    dynamodb create table logger

  11. Save and Run the project as a Mule Application. Right-click the project in Package Explorer and click Run As > Mule Application.

  12. Open a browser and check the response after entering the http://localhost:8091/createtable URL. You should see the generated response from the Create Table operation in the Mule console.

Use Case: XML

XML flow for the DynamoDB create and delete table in Anypoint Studio:


         
      
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
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:dynamodb="http://www.mulesoft.org/schema/mule/dynamodb"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/dynamodb
http://www.mulesoft.org/schema/mule/dynamodb/current/mule-dynamodb.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
        <dynamodb:config name="Amazon_DynamoDB_Configuration" doc:name="Amazon DynamoDB Configuration">
                <dynamodb:basic-connection accessKey="${config.accesskey}" secretKey="${config.secretkey}" />
        </dynamodb:config>
        <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
                <http:listener-connection host="localhost" port="8091" />
        </http:listener-config>
        <flow name="create-table-flow">
                <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/createtable"/>
                <dynamodb:create-table doc:name="Create table"
                config-ref="Amazon_DynamoDB_Configuration"
                tableName="StudentData"
                readCapacityUnits="5" writeCapacityUnits="5">
                        <dynamodb:attribute-definitions >
                                <dynamodb:attribute-definition attributeName="studentId" attributeType="N" />
                        </dynamodb:attribute-definitions>
                        <dynamodb:key-schemas >
                                <dynamodb:key-schema-element attributeName="studentId" keyType="HASH" />
                        </dynamodb:key-schemas>
                </dynamodb:create-table>
                <logger level="INFO" doc:name="Logger" message="#[payload]"/>
        </flow>
        <flow name="delete-table-flow">
                <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/delete"/>
                <dynamodb:delete-table doc:name="Delete table"
                config-ref="Amazon_DynamoDB_Configuration" tableName="StudentData"/>
                <logger level="INFO" doc:name="Logger" message="#[payload]"/>
        </flow>
</mule>

See Also