Contact Free trial Login

Amazon DynamoDB Connector - Mule 4

Support Category: Select

Amazon DynamoDB Connector v1.4

Anypoint Connector for Amazon DynamoDB (Amazon DynamoDB Connector) provides connectivity to the Amazon DynamoDB API, which enables 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.

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

Prerequisites

To use this information, you must be familiar with Amazon DynamoDB API, Mule, Anypoint Connectors, Anypoint Studio, Mule concepts, elements in a Mule flow, and Global Elements.

For 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

  • AWS Identity and Access Management (IAM) user account credentials to access AWS with the connector

  • Anypoint Studio version 7.0 or later, or Design Center

POM File Information

<dependency>
  <groupId>com.mulesoft.connectors</groupId>
  <artifactId>mule-amazon-dynamodb-connector</artifactId>
  <version>RELEASE</version>
  <classifier>mule-plugin</classifier>
</dependency>

Mule converts RELEASE to the latest version. To specify a version, view Amazon DynamoDB Connector in Anypoint Exchange and click Dependency Snippets.

Add the Connector to a Studio Project

Anypoint Studio provides two ways to add the connector to your Studio project:

  • From the Exchange button in the Studio taskbar

  • From the Mule Palette view

Add the Connector Using Exchange

  1. In Studio, create a Mule project.

  2. Click the Exchange icon (X) in the upper-left of the Studio task bar.

  3. In Exchange, click Login and supply your Anypoint Platform username and password.

  4. In Exchange, search for "dynamo".

  5. Select the connector and click Add to project.

  6. Follow the prompts to install the connector.

Add the Connector in Studio

  1. In Studio, create a Mule project.

  2. In the Mule Palette view, click (X) Search in Exchange.

  3. In Add Modules to Project, type "dynamo" in the search field.

  4. Click this connector’s name in Available modules.

  5. Click Add.

  6. Click Finish.

Configure the Connector in Studio

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

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

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

    Global Element Configuration Wizard
  4. Configure the parameters as follows:

    Parameter Description

    Name

    Enter a name for the configuration for the connector to reference.

    Session Token

    Enter the session token provided by Amazon STS.

    Access Key

    Enter the alphanumeric text string that uniquely identifies the user who owns the account.

    Secret Key

    Enter the key that serves the role of a password.

    Try Default AWS Credentials Provider Chain

    Select the checkbox that controls whether temporary credentials should be used.

    Placeholder values refer to the mule-artifact.properties configuration file in the src/main/resources folder of your project.

    You can either enter your credentials in the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better reusability 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 Reconnection strategy with the 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 your instance of Amazon DynamoDB.

  7. Click OK to save the global connector configurations.

    Your configuration should look like this:

    DynamoDB use case configuration

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.

    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 an HTTP Listener configuration has not been created:

    1. Click the plus sign to add a new HTTP Listener Configuration.

    2. For Host, use localhost, and for Port, use 8081.

    3. Click OK.

    Path

    /createtable

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

  5. Add a new Amazon DynamoDB Global Element to configure the Amazon DynamoDB connector:
    Click the plus sign + next to the Connector Configuration field.

  6. Configure the global element as follows:

    Parameter Description Value

    Name

    Enter a name for the configuration for the connector to reference.

    <Configuration_Name>

    Access Key

    Enter the alphanumeric text string that uniquely identifies the user who owns the account.

    ${amazon.accesskey}

    Secret Key

    Enter the key that serves 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:

    <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

    Enter the display name to use for the Create Table operation.

    Basic Settings

    Extension Configuration

    Enter the configuration name you used in the global element for the connector to reference.

    General

    TableName

    The name for the table.

    AttributeDefinitions

    This value is an array of attributes that describe the key schema for the table and indexes.

    KeySchema

    This value 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. Verify that your XML looks like this:

    <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 as follows:

    Parameter Value

    Display Name

    Enter the display name for the Logger.

    Message

    #[payload]

    Level

    INFO

    dynamodb create table logger
  11. Save and run the project as a Mule application:
    In Package Explorer, right-click the project and click Run As > Mule Application.

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

XML Flow

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

<?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">
    <configuration-properties file="mule-artifact.properties" />
	<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>

Migration information

Changes from version 1.3.0 to 1.4.0 include the following:

  • Added TLS configuration into the connector.

  • Upgraded aws-java-sdk from 1.11.604 to 1.11.649

  • Upgraded aws-connector-commons from 2.0.2 to 2.2.0