---
schema_version: "1"
id: fb8e66ac4de7367cfac3a1ffe638a626d9683a5568fcebc3e9100dc822fa999a
title: Amazon DynamoDB Examples
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/amazon-dynamodb-connector-examples.md
canonical_url: https://docs.mulesoft.com/amazon-dynamodb-connector/1.5/amazon-dynamodb-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 68aeb71c0dcd021c58166e18b0102e57ee970ec02b68f60ba299c0457b57f2f2
description: MuleSoft Documentation Site
release: "1.5"
latest: false
---
---
product: Amazon DynamoDB Connector
version: 1.5
---

# Amazon DynamoDB Examples

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The following are common use cases for Amazon DynamoDB Connector:

- Creating an Amazon DynamoDB table

- Deleting an Amazon DynamoDB table

- Performing an Amazon DynamoDB table scan

## Create an Amazon DynamoDB Table

This example shows how to use Amazon DynamoDB connector to create an Amazon DynamoDB table.

### Flow for Creating an Amazon DynamoDB Table

The following screenshot shows an Anypoint Studio flow for creating an Amazon DynamoDB table:

![Studio flow for creating an Amazon DynamoDB table](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-create-table-flow.png)

Figure 1. Use this sample flow to create an Amazon DynamoDB table.

### Preliminary Steps

Follow these steps to start creating an Amazon DynamoDB table:

1.  Create a new Mule project in Studio.

2.  Add the following properties to the `mule-artifact.properties` file to store your Amazon
    DynamoDB credentials:

    ```text
    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    ```

3.  Place the `mule-artifact.properties` file in the project’s `src/main/resources` directory.

### Configure HTTP Listener

Configure `HTTP Listener` to listen for HTTP requests on the `/createtable` path:

1.  In the **Mule Palette** view, search for `http` and select the **Listener** operation.

2.  Drag the **Listener** operation onto the Studio canvas.

3.  On the **Listener** tab, click the plus sign (+) next to the **Connector configuration** field
    to access the global element configuration fields for `HTTP Listener`.

4.  In the **Host** field, select `localhost`:

    ![HTTP Listener global element](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-http-global-element.png)

    Figure 2. Select `localhost` in the **Host** field to listen for HTTP requests on your local
    computer.

5.  Click **OK**.

6.  In the **Path** field on the **Listener** tab, enter `/createtable`:

    ![HTTP Listener tab](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-http-prop.png)

    Figure 3. Enter `/createtable` in the **Path** field to listen for HTTP requests on the
    `/createtable` path.

### Configure the Create Table Operation

Configure the `Create Table` operation to create a table named `Issues`:

1.  In the **Mule Palette** view, click **Search in Exchange** and search for `amazon dynamodb`.

2.  Select **Amazon DynamoDB Connector**, click **Add>**, and then click **Finish**.

3.  Drag the **Create Table** operation to the right of **Listener** on the Studio canvas.

4.  Click the **Global Elements** link below the flow.

5.  Add the properties file you created earlier to the **Configuration properties** field, as
    described in
    [Use Property Placeholders for Property Values](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview#property-placeholders).

6.  Click **Create**.

7.  Expand **Connector Configuration**.

8.  Select **Amazon DynamoDB Configuration** and click **OK**.

9.  Complete the following fields:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Description</th><th>Value</th></tr></thead><tbody><tr><td><p><strong>Name</strong></p></td><td><div><div><p>Configuration name</p></div></div></td><td><div><div><p><code>create-table-flow</code></p></div></div></td></tr><tr><td><p><strong>Access Key</strong></p></td><td><div><div><p>Alphanumeric text string that uniquely identifies the user who owns the account</p></div></div></td><td><div><div><p><code>${config.accesskey}</code></p></div></div></td></tr><tr><td><p><strong>Secret Key</strong></p></td><td><div><div><p>Key that acts as a password</p></div></div></td><td><div><div><p><code>${config.secretkey}</code></p></div></div></td></tr><tr><td><p><strong>Region Endpoint</strong></p></td><td><div><div><p>Region for the Amazon DynamoDB client</p></div></div></td><td><div><div><p><code>us-east-1</code></p></div></div></td></tr></tbody></table>

    The following screenshot shows an example of configuring a global element for Amazon DynamoDB
    Connector:

    ![Amazon DynamoDB global element](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-global-element.png)

    Figure 4. Configure the credentials needed to access Amazon DynamoDB in the **Connection**
    section of the global element.

10. Click **Test Connection** to confirm that Mule can connect with the Amazon DynamoDB instance:

    - If the connection is successful, click **OK** to save the configuration.

    - If the connection is unsuccessful, review or correct any incorrect parameters, and then test
      again.

11. Click **OK**.

12. On the **Create table** tab, configure the following fields:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Field</th><th>Description</th><th>User Action</th></tr></thead><tbody><tr><td><p>Table name</p></td><td><p>The name of the table</p></td><td><div><div><p>Enter <code>Issues</code>.</p></div></div></td></tr><tr><td><p>Attribute definitions</p></td><td><p>An array of attributes that describe the key schema for the table and its indexes</p></td><td><div><div><p>Select <code>Edit inline</code>, click the green plus sign (+), and add the following attributes:</p></div><div><ul><li><p><code>IssueId</code> as type <code>STRING</code></p></li><li><p><code>Title</code> as type <code>STRING</code></p></li><li><p><code>CreateDate</code> as type <code>STRING</code></p></li><li><p><code>DueDate</code> as type <code>STRING</code></p></li></ul></div></div></td></tr><tr><td><p>Key schemas</p></td><td><p>The attributes that make up the primary key for the table or one of its indexes</p></td><td><div><div><p>Select <code>Edit inline</code>, click the green plus sign (+), add the following attributes:</p></div><div><ul><li><p><code>IssueId</code> as key type <code>HASH</code></p></li><li><p><code>Title</code> as key type <code>RANGE</code></p></li></ul></div></div></td></tr><tr><td><p>Read capacity units</p></td><td><p>The maximum number of strongly consistent reads consumed per second before Amazon DynamoDB returns a throttling exception</p></td><td><div><div><p>Enter <code>5</code>.</p></div></div></td></tr><tr><td><p>Write capacity units</p></td><td><p>The maximum number of writes consumed per second before Amazon DynamoDB returns a throttling exception</p></td><td><div><div><p>Enter <code>5</code>.</p></div></div></td></tr><tr><td><p>Global secondary indexes</p></td><td><p>An optional, additional key structure for the table</p></td><td><div><div><p>Enter <code>#[vars.secondary]</code> to create a variable for the secondary index, and then add the secondary index to the XML code, as described in <a href="#secondary-index">Add a Secondary Index to the Issues Table</a>.</p></div></div></td></tr></tbody></table>

    The following screenshot shows an example of configuring the `Create table` operation:

    ![Create table operation fields](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-create-table-props.png)

    Figure 5. Enter values for the `Create table` operation fields.

    In this screenshot:

    - The first item specifies the name of the component that represents the `Create table`
      operation in the flow.

    - The second item specifies the name of the table to create.

    - The third item defines the attributes of the new table.

    - The fourth item defines the key schemas of the new table.

    - The fifth item specifies the maximum number of strongly consistent reads consumed per second
      and strongly consistent writes consumed per second before Amazon DynamoDB returns a throttling
      exception.

    - The sixth item specifies a variable for the secondary index.

The XML flow for the create table example looks like this after you configure the `HTTP Listener`
and `Create table` operations:

```xml
<?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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
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="8081" />
	</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="Issues" readCapacityUnits="5" writeCapacityUnits="5" globalSecondaryIndexes="#[vars.secondary]">
		<dynamodb:attribute-definitions>
			<dynamodb:attribute-definition attributeName="IssueId" attributeType="STRING" />
			<dynamodb:attribute-definition attributeName="Title" attributeType="STRING" />
			<dynamodb:attribute-definition attributeName="CreateDate" attributeType="STRING" />
			<dynamodb:attribute-definition attributeName="DueDate" attributeType="STRING" />
		</dynamodb:attribute-definitions>
		<dynamodb:key-schemas>
			<dynamodb:key-schema-element attributeName="IssueId" keyType="HASH" />
			<dynamodb:key-schema-element attributeName="Title" keyType="RANGE" />
		</dynamodb:key-schemas>
	</dynamodb:create-table>
</flow>
</mule>
```

### Add a Secondary Index to the Issues Table

To add a global secondary index to the `Issues` table, add a variable before the
`<dynamodb:create-table>` element in the XML.

The following example adds three secondary indexes to the `Issues` table:

- `CreateDateIndex`, with the `CreateDate` partition key and the `IssueId` sort key

- `TitleIndex` with the `Title` partition key and the `IssueId` sort key

- `DueDateIndex` with the `DueDate` partition key

You must include these elements in the XML:

- `<Projection>`, which specifies the attributes to copy from the table into the index.

  In this example, the value `ALL` means that all attributes are copied.

  The primary key attributes and index key attributes are automatically copied, no matter what value
  you set for the `<Projection>` element.

- `ProvisionedThroughput` provisions throughput for read and write activity.

- `KeySchema` specifies the key schema for the index.

```xml
<set-variable value='#[[
            {
                "IndexName": "CreateDateIndex",
                "Projection": {
                    "ProjectionType": "ALL"
                },
                "ProvisionedThroughput": {
                    "WriteCapacityUnits": 5,
                    "ReadCapacityUnits": 5
                },
                "KeySchema": [
                    {
                        "KeyType": "HASH",
                        "AttributeName": "CreateDate"
                    },
                    {
                    	"KeyType": "RANGE",
                    	"AttributeName": "IssueId"
                    }
                ]
            } as Object {
            	class: "org.mule.extension.dynamodb.api.model.GlobalSecondaryIndex"
            },
            {
                "IndexName": "TitleIndex",
                "Projection": {
                    "ProjectionType": "ALL"
                },
                "ProvisionedThroughput": {
                    "WriteCapacityUnits": 5,
                    "ReadCapacityUnits": 5
                },
                "KeySchema": [
                    {
                        "KeyType": "HASH",
                        "AttributeName": "Title"
                    },
                    {
                    	"KeyType": "RANGE",
                    	"AttributeName": "IssueId"
                    }
                ]
            } as Object {
            	class: "org.mule.extension.dynamodb.api.model.GlobalSecondaryIndex"
            },
            {
                "IndexName": "DueDateIndex",
                "Projection": {
                    "ProjectionType": "ALL"
                },
                "ProvisionedThroughput": {
                    "WriteCapacityUnits": 5,
                    "ReadCapacityUnits": 5
                },
                "KeySchema": [
                    {
                        "KeyType": "HASH",
                        "AttributeName": "DueDate"
                    }
                ]
            } as Object {
            	class: "org.mule.extension.dynamodb.api.model.GlobalSecondaryIndex"
            }
        ]]' doc:name="Secondary" variableName="secondary"/>
```

### Configure a Logger Component

Configure a `Logger` component to print to the Mule console the response generated by the
`Create Table` operation:

1.  In the **Mule Palette** view, search for `logger`.

2.  Drag the **Logger** component to the right of **Create Table** on the Studio canvas.

3.  Enter `#[payload]` in the **Message** field on the **Logger** tab.

    ![Logger tab](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-logger-props.png)

    Figure 6. Enter `#[payload]` in the **Message** field to print the operation’s response to the
    Mule console.

### XML for the Complete Create Table Example

The XML for the complete create table example looks like this:

```xml
<?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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
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="8081" />
	</http:listener-config>
	<flow name="create-table-flow" >
	<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/createtable"/>

		<set-variable value='#[[
            {
                "IndexName": "CreateDateIndex",
                "Projection": {
                    "ProjectionType": "ALL"
                },
                "ProvisionedThroughput": {
                    "WriteCapacityUnits": 5,
                    "ReadCapacityUnits": 5
                },
                "KeySchema": [
                    {
                        "KeyType": "HASH",
                        "AttributeName": "CreateDate"
                    },
                    {
                    	"KeyType": "RANGE",
                    	"AttributeName": "IssueId"
                    }
                ]
            } as Object {
            	class: "org.mule.extension.dynamodb.api.model.GlobalSecondaryIndex"
            },
            {
                "IndexName": "TitleIndex",
                "Projection": {
                    "ProjectionType": "ALL"
                },
                "ProvisionedThroughput": {
                    "WriteCapacityUnits": 5,
                    "ReadCapacityUnits": 5
                },
                "KeySchema": [
                    {
                        "KeyType": "HASH",
                        "AttributeName": "Title"
                    },
                    {
                    	"KeyType": "RANGE",
                    	"AttributeName": "IssueId"
                    }
                ]
            } as Object {
            	class: "org.mule.extension.dynamodb.api.model.GlobalSecondaryIndex"
            },
            {
                "IndexName": "DueDateIndex",
                "Projection": {
                    "ProjectionType": "ALL"
                },
                "ProvisionedThroughput": {
                    "WriteCapacityUnits": 5,
                    "ReadCapacityUnits": 5
                },
                "KeySchema": [
                    {
                        "KeyType": "HASH",
                        "AttributeName": "DueDate"
                    }
                ]
            } as Object {
            	class: "org.mule.extension.dynamodb.api.model.GlobalSecondaryIndex"
            }
        ]]' doc:name="Secondary" variableName="secondary"/>

		<dynamodb:create-table doc:name="Create table" config-ref="Amazon_DynamoDB_Configuration" tableName="Issues" readCapacityUnits="5" writeCapacityUnits="5" globalSecondaryIndexes="#[vars.secondary]">
		<dynamodb:attribute-definitions>
			<dynamodb:attribute-definition attributeName="IssueId" attributeType="STRING" />
			<dynamodb:attribute-definition attributeName="Title" attributeType="STRING" />
			<dynamodb:attribute-definition attributeName="CreateDate" attributeType="STRING" />
			<dynamodb:attribute-definition attributeName="DueDate" attributeType="STRING" />
		</dynamodb:attribute-definitions>
		<dynamodb:key-schemas>
			<dynamodb:key-schema-element attributeName="IssueId" keyType="HASH" />
			<dynamodb:key-schema-element attributeName="Title" keyType="RANGE" />
		</dynamodb:key-schemas>
	</dynamodb:create-table>
		<logger level="INFO" doc:name="Logger"
    message="#[payload]"/>
</flow>
</mule>
```

### Run the Project

Save and run the project as a Mule app:

1.  In **Package Explorer**, right-click the project name and click **Run As** > **Mule
    Application**.

2.  Open a browser and check the response after you enter the `http://localhost:8081/createtable`
    URL.

    You see the generated response from the `Create table` operation in the Mule console.

## Delete an Amazon DynamoDB Table

This example shows how to use Amazon DynamoDB connector to delete an Amazon DynamoDB table.

### Flow for Deleting a DynamoDB Table

The following screenshot shows an Anypoint Studio flow for deleting an Amazon DynamoDB table:

![Studio flow for deleting an Amazon DynamoDB table](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-delete-table-flow.png)

Figure 7. Use this sample flow to delete an Amazon DynamoDB table.

### Preliminary Steps

Follow these steps to start deleting an Amazon DynamoDB table:

1.  Create a new Mule project in Studio.

2.  Add the following properties to the `mule-artifact.properties` file to hold your Amazon DynamoDB
    credentials:

    ```text
    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    ```

3.  Place the `mule-artifact.properties` file in the project’s `src/main/resources` directory.

### Configure HTTP Listener

Configure `HTTP Listener` to listen for HTTP requests on the `/deletetable` path:

1.  In the **Mule Palette** view, search for `http` and select the **Listener** operation.

2.  Drag the **Listener** operation onto the Studio canvas.

3.  On the **Listener** tab, click the plus sign (+) next to the **Connector configuration** field
    to access the global element configuration fields for `HTTP Listener`.

4.  In the **Host** field, select `localhost` and click **OK**.

5.  In the **Path** field on the **Listener** tab, enter `/deletetable`.

### Configure the Delete Table Operation

Configure the `Delete table` operation to delete the `Issues` table.

1.  In the **Mule Palette** view, click **Search in Exchange** and search for `amazon dynamodb`.

2.  Select **Amazon DynamoDB Connector**, click **Add>**, and then click **Finish**.

3.  Drag the **Delete Table** operation to the right of **Listener** on the Studio canvas.

4.  Click the **Global Elements** link below the flow.

5.  Add the properties file you created earlier to the **Configuration properties** field, as
    described in
    [Use Property Placeholders for Property Values](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview#property-placeholders).

6.  Click **Create**.

7.  Expand **Connector Configuration**.

8.  Select **Amazon DynamoDB Configuration** and click **OK**.

9.  Complete the following fields:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Description</th><th>Value</th></tr></thead><tbody><tr><td><p>Name</p></td><td><p>Configuration name</p></td><td><div><div><p><code>delete-table-flow</code></p></div></div></td></tr><tr><td><p>Access Key</p></td><td><p>Alphanumeric text string that uniquely identifies the user who owns the account</p></td><td><div><div><p><code>${config.accesskey}</code></p></div></div></td></tr><tr><td><p>Secret Key</p></td><td><p>Key that acts as a password</p></td><td><div><div><p><code>${config.secretkey}</code></p></div></div></td></tr><tr><td><p>Region Endpoint</p></td><td><p>Region for the Amazon DynamoDB client</p></td><td><div><div><p><code>us-east-1</code></p></div></div></td></tr></tbody></table>

    The corresponding XML configuration looks like this:

    ```xml
    <dynamodb:config name="Amazon_DynamoDB_Configuration1" doc:name="Amazon DynamoDB Configuration" >
      <dynamodb:basic-connection
      	accessKey="${config.accesskey}"
    	  secretKey="${config.secretkey}"
      />
    </dynamodb:config>
    ```

10. Click **Test Connection** to confirm that Mule can connect with the Amazon DynamoDB instance:

    - If the connection is successful, click **OK** to save the configuration.

    - If the connection is unsuccessful, review or correct any incorrect parameters, and then test
      again.

11. Click **OK**.

12. On the **Delete table** tab, set the value of `Table name` to `Issues`.

### Configure a Logger Component

Configure a `Logger` component to print to the Mule console the response generated by the
`Delete table` operation:

1.  In the **Mule Palette** view, search for `logger`.

2.  Drag the **Logger** component to the right of **Delete Table** on the Studio canvas.

3.  On the **Logger** tab, enter `#[payload]` in the **Message** field.

### XML for the Delete Table Example

The XML for the delete table example looks like this:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dynamodb="http://www.mulesoft.org/schema/mule/dynamodb" 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: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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/dynamodb http://www.mulesoft.org/schema/mule/dynamodb/current/mule-dynamodb.xsd">
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" >
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<dynamodb:config name="Amazon_DynamoDB_Configuration" doc:name="Amazon DynamoDB Configuration" >
		<dynamodb:basic-connection accessKey="${config.accesskey}" secretKey="${config.secretkey}" />
	</dynamodb:config>
	<flow name="delete-table-flow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/deletetable"/>
		<dynamodb:delete-table doc:name="Delete table" config-ref="Amazon_DynamoDB_Configuration" tableName="Issues"/>
		<logger level="INFO" doc:name="Logger" message="#[payload]"/>
	</flow>
</mule>
```

### Run the Project

Save and run the project as a Mule app:

1.  In **Package Explorer**, right-click the project name and click **Run As** > **Mule
    Application**.

2.  Open a browser and check the response after you enter the `http://localhost:8081/deletetable`
    URL.

    You see the generated response from the `Delete table` operation in the Mule console.

## Scan an Amazon DynamoDB Table

This example shows how to use Amazon DynamoDB Connector to scan an Amazon DynamoDB table.

The following considerations apply to performing a scan using Amazon DynamoDB Connector:

- The DynamoDB AWS SDK paginates results by dividing them into specific pages.

  A 1-MB limit applies to returned results. When this limit is exceeded, you must perform another
  scan to receive the rest of the data.

- To perform subsequent scans, apply the value of the `LastEvaluatedKey` field in the JSON response
  to the `Exclusive start keys` field in the Studio configuration of the `Scan` operation.

  When the operation has returned all pages of data, the `LastEvaluatedKey` value in the JSON
  response is null.

### Flow for Scanning a Table

The following screenshot shows an Anypoint Studio flow for scanning an Amazon DynamoDB table:

![Studio flow for scanning an Amazon DynamoDB table](/mulesoft/current/en-us/amazon-dynamodb-connector/1.5/_images/amazon-dynamodb-scan-flow.png)

Figure 8. Use this sample flow to scan an Amazon DynamoDB table.

### Preliminary Steps

Follow these steps to start scanning an Amazon DynamoDB table:

1.  Create a new Mule project in Studio.

2.  Add the following properties to the `mule-artifact.properties` file to hold your Amazon DynamoDB
    credentials:

    ```text
    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    ```

3.  Place the `mule-artifact.properties` file in the project’s `src/main/resources` directory.

### Configure HTTP Listener

Configure `HTTP Listener` to listen for HTTP requests on the `/scantable` path:

1.  In the **Mule Palette** view, search for `http` and select the **Listener** operation.

2.  Drag the **Listener** operation onto the Studio canvas.

3.  On the **Listener** tab, click the plus sign (+) next to the **Connector configuration** field
    to access the global element configuration fields for `HTTP Listener`.

4.  In the **Host** field, select `localhost` and click **OK**.

5.  In the **Path** field on the **Listener** tab, enter `/scantable`.

### Configure the Scan Operation

1.  In the **Mule Palette** view, click **Search in Exchange** and search for `amazon dynamodb`.

2.  Select **Amazon DynamoDB Connector**, click **Add>**, and then click **Finish**.

3.  Drag the **Scan** operation to the right of **Listener** on the Studio canvas.

4.  Click the **Global Elements** link below the flow.

5.  Add the properties file you created earlier to the **Configuration properties** field, as
    described in
    [Use Property Placeholders for Property Values](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview#property-placeholders).

6.  Click **Create**.

7.  Expand **Connector Configuration**.

8.  Select **Amazon DynamoDB Configuration** and click **OK**.

9.  Complete the following fields:

    <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Description</th><th>Value</th></tr></thead><tbody><tr><td><p>Name</p></td><td><p>Configuration name</p></td><td><div><div><p><code>scan-table-flow</code></p></div></div></td></tr><tr><td><p>Access Key</p></td><td><p>Alphanumeric text string that uniquely identifies the user who owns the account</p></td><td><div><div><p><code>${config.accesskey}</code></p></div></div></td></tr><tr><td><p>Secret Key</p></td><td><p>Key that acts as a password</p></td><td><div><div><p><code>${config.secretkey}</code></p></div></div></td></tr><tr><td><p>Region Endpoint</p></td><td><p>Region for the Amazon DynamoDB client</p></td><td><div><div><p><code>us-east-1</code></p></div></div></td></tr></tbody></table>

10. Click **Test Connection** to confirm that Mule can connect with the Amazon DynamoDB instance:

    - If the connection is successful, click **OK** to save the configuration.

    - If the connection is unsuccessful, review or correct any incorrect parameters, and then test
      again.

11. Click **OK**.

12. On the **Scan** tab, set the value of `Table name` to `Issues`.

### Configure a Transform Message Component

Configure a `Transform Message` component to change the `Scan` operation output from Java to JSON:

1.  In the **Mule Palette** view, search for `transform`.

2.  Drag the **Transform Message** component to the right of **Scan** on the Studio canvas.

3.  In the **Output** section of the **Scan** operation, change `output/application/java` to
    `output/application/json`.

### Configure a Logger Component

Configure a `Logger` component to print to the Mule console the response generated by the `Scan`
operation:

1.  In the **Mule Palette** view, search for `Logger`.

2.  Drag the **Logger** component to the right of **Transform** on the Studio canvas.

3.  Enter `#[payload]` in the **Message** field on the **Logger** tab.

### XML for the Scan Table Example

The XML for the scan table example looks like this:

```text
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:dynamodb="http://www.mulesoft.org/schema/mule/dynamodb"
	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: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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/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="localhost" port="8081" />
	</http:listener-config>
	<dynamodb:config name="Amazon_DynamoDB_Configuration" doc:name="Amazon DynamoDB Configuration" >
		<dynamodb:basic-connection accessKey="${config.accesskey}" secretKey="${config.secretkey}" />
	</dynamodb:config>
	<dynamodb:config name="Amazon_DynamoDB_Configuration1" doc:name="Amazon DynamoDB Configuration" >
		<dynamodb:basic-connection accessKey="${config.accesskey}" secretKey="${config.secretkey}" />
	</dynamodb:config>
	<flow name="delete-table-flow" >
		<http:listener doc:name="Listener" path="/scantable" config-ref="HTTP_Listener_config"/>
		<dynamodb:scan doc:name="Scan" config-ref="Amazon_DynamoDB_Configuration1" tableName="Issues"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
{
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" message="#[payload]"/>
	</flow>
</mule>
```

### Response to the Scan Table Example

The response to a `Scan` operation might look like this (with other sections of the response omitted
for brevity):

```xml
{
  "scannedCount": 2,
  "lastEvaluatedKey": null,
  "count": 2,
  "consumedCapacity": null,
  "items": [
    {
      "studentID": {
        "ss": null,
        "nullvalue": null,
        "b": null,
        "bool": null,
        "ns": null,
        "l": null,
        "m": null,
        "n": null,
        "bs": null,
        "s": "102"
      },
      ...
  ]
}
```

### Run the Project

Save and run the project as a Mule app:

1.  In **Package Explorer**, right-click the project name and click **Run As** > **Mule
    Application**.

2.  Open a browser and check the response after you enter the `http://localhost:8081/scantable` URL.

    You see the generated response from the `Scan` operation in the Mule console.

## See Also

- [Amazon API documentation](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/Welcome.html)

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
