---
schema_version: "1"
id: 3490896a050003e412f5e3102c0992ccc710b4652fdfb8c3a4d0b40a9e475ebf
title: Amazon DynamoDB の例
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/amazon-dynamodb-connector-examples.md
canonical_url: https://docs.mulesoft.com/jp/amazon-dynamodb-connector/1.4/amazon-dynamodb-connector-examples
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9ffe0dfe70aa71d8e949dc6b438068bb6d93dcb43e8497b405d0177d363755e1
description: MuleSoft Documentation Site
release: "1.4"
latest: false
---
# Amazon DynamoDB の例

次に、Amazon DynamoDB Connector の一般的なユースケースを示します。

- Amazon DynamoDB テーブルの作成
- Amazon DynamoDB テーブルの削除
- Amazon DynamoDB テーブルスキャンの実行

## [](#create-table)Amazon DynamoDB テーブルの作成

次の例は、Amazon DynamoDB Connector を使用して Amazon DynamoDB テーブルを作成する方法を示しています。

### [](#amazon-dynamodb-テーブルの作成フロー)Amazon DynamoDB テーブルの作成フロー

次のスクリーンショットは、Amazon DynamoDB テーブルを作成するための Anypoint Studio フローを示しています。

![Amazon DynamoDB テーブルを作成するための Studio フロー](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-create-table-flow.png)

Figure 1. このサンプルフローを使用して、Amazon DynamoDB テーブルを作成します。

### [](#preliminary-steps-create)事前手順

次の手順に従って、Amazon DynamoDB テーブルの作成を開始します。

1. Studio で新しい Mule プロジェクトを作成します。
2. 次のプロパティを ​`mule-artifact.properties`​ ファイルに追加して、Amazon DynamoDB ログイン情報を保存します。
    
    ```text
    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    ```
3. プロジェクトの ​`src/main/resources`​ ディレクトリに ​`mule-artifact.properties`​ ファイルを置きます。

### [](#configure-http-listener)HTTP リスナーを設定する

`/createtable`​ パスで HTTP 要求をリスンするように ​`HTTP Listener`​ を設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで「​`http`​」を検索し、​**\[Listener\]**​ 操作を選択します。
2. **\[Listener\]**​ 操作を Studio キャンバスにドラッグします。
3. **\[Listener\]**​ タブで、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (+) をクリックして、​`HTTP Listener`​ のグローバル要素設定項目にアクセスします。
4. **\[Host (ホスト)\]**​ 項目で ​`localhost`​ を選択します。
    
    ![HTTP リスナーのグローバル要素](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-http-global-element.png)
    
    Figure 2. **\[Host (ホスト)\]**​ 項目で ​`localhost`​ を選択して、ローカルコンピューターで HTTP 要求をリスンします。
5. **\[OK\]**​ をクリックします。
6. **\[Listener\]**​ タブの ​**\[Path (パス)\]**​ 項目で、「​`/createtable`​」と入力します。
    
    ![HTTP リスナータブ](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-http-prop.png)
    
    Figure 3. **\[Path (パス)\]**​ 項目に「​`/createtable`​」と入力して、​`/createtable`​ パスで HTTP 要求をリスンします。

### [](#create-table-操作を設定する)Create Table 操作を設定する

`Issues`​ というテーブルを作成する ​`Create Table`​ 操作を設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、​**\[Search in Exchange (Exchange 内を検索)\]**​ をクリックして「​`amazon dynamodb`​」を検索します。
2. **\[Amazon DynamoDB Connector\]**​ を選択して ​**\[Add> (追加>)\]**​ をクリックし、​**\[Finish (完了)\]**​ をクリックします。
3. **\[Create Table\]**​ 操作を Studio キャンバスの ​**\[Listener\]**​ の右にドラッグします。
4. フローの下の ​**\[Global Elements (グローバル要素)\]**​ リンクをクリックします。
5. [「プロパティ値のプロパティプレースホルダーの使用」](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview#property-placeholders)​の説明に従って、以前に作成したプロパティファイルを ​**\[Configuration properties (設定プロパティ)\]**​ 項目に追加します。
6. **\[Create (作成)\]**​ をクリックします。
7. **\[Connector Configuration (コネクタ設定)\]**​ を展開します。
8. **\[Amazon DynamoDB Configuration (Amazon DynamoDB 設定)\]**​ を選択し、​**\[OK\]**​ をクリックします。
9. 次の項目に入力します。
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 30%;">
<col style="width: 40%;">
<col style="width: 30%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">パラメーター</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">値</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Name (名前)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>設定名</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>create-table-flow</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Access Key (アクセスキー)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>アカウントを所有するユーザーを一意に識別する英数字のテキスト文字列</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>${config.accesskey}</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Secret Key (シークレットキー)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>パスワードの役割を果たすキー。</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>${config.secretkey}</code>​</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>Region Endpoint (リージョンエンドポイント)</strong></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Amazon DynamoDB クライアントに設定するリージョン</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>us-east-1</code></p>
</div></div></td>
</tr>
</tbody>
</table>
    
    次のスクリーンショットは、Amazon DynamoDB Connector のグローバル要素を設定する例を示しています。
    
    ![Amazon DynamoDB グローバル要素](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-global-element.png)
    
    Figure 4. グローバル要素の ​**\[Connection (接続)\]**​ セクションで、Amazon DynamoDB にアクセスするために必要なログイン情報を設定します。
10. **\[Test Connection (接続をテスト)\]**​ をクリックして、Mule が Amazon DynamoDB インスタンスに接続できることを確認します。
    
    - 正常に接続できた場合は、​**\[OK\]**​ をクリックして設定を保存します。
    - 接続に失敗した場合は、誤ったパラメーターを確認して修正し、もう一度テストを実行してください。
11. **\[OK\]**​ をクリックします。
12. **\[Create Table\]**​ タブで、次の項目を設定します。
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 35%;">
<col style="width: 40%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">項目</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">ユーザーアクション</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Table name (テーブル名)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">テーブルの名前</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>「​<code>Issues</code>​」と入力します。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Attribute definitions (属性定義)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">テーブルとそのインデックスのキースキーマを記述する属性の配列</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>Edit inline</code>​ を選択して緑のプラス記号 (+) をクリックし、次の属性を追加します。</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>IssueId</code>​ (​<code>STRING</code>​ 型)</p>
</li>
<li>
<p><code>Title</code>​ (​<code>STRING</code>​ 型)</p>
</li>
<li>
<p><code>CreateDate</code>​ (​<code>STRING</code>​ 型)</p>
</li>
<li>
<p><code>DueDate</code>​ (​<code>STRING</code>​ 型)</p>
</li>
</ul>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Key schemas (キースキーマ)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">テーブルまたはそのインデックスのいずれかの主キーを構成する属性</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>Edit inline</code>​ を選択して緑のプラス記号 (+) をクリックし、次の属性を追加します。</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>IssueId</code>​ (​<code>HASH</code>​ キー種別)</p>
</li>
<li>
<p><code>Title</code>​ (​<code>RANGE</code>​ キー種別)</p>
</li>
</ul>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Read capacity units (読み取り容量単位)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Amazon DynamoDB が調整例外を返す前にコンシュームされる 1 秒あたりの厳密な一貫性読み取りの最大数</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>「​<code>5</code>​」と入力します。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Write capacity units (書き込み容量単位)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Amazon DynamoDB が調整例外を返す前にコンシュームされる 1 秒あたりの書き込みの最大数。</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>「​<code>5</code>​」と入力します。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Global secondary indexes (グローバルセカンダリインデックス)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">テーブルの省略可能な追加キー構造</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><a href="#secondary-index">「Issues テーブルへのセカンダリインデックスの追加」</a>​の説明に従って、「​<code>#[vars.secondary]</code>​」と入力してセカンダリインデックスの変数を作成し、XML コードにセカンダリインデックスを追加します。</p>
</div></div></td>
</tr>
</tbody>
</table>
    
    次のスクリーンショットは、​`Create table`​ 操作の設定例を示しています。
    
    ![Create table 操作の項目](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-create-table-props.png)
    
    Figure 5. `Create table`​ 操作の項目値を入力します。
    
    このスクリーンショットについて説明します。
    
    - 最初の項目では、フロー内の ​`Create table`​ 操作を表すコンポーネントの名前を指定します。
    - 2 番目の項目では、作成するテーブルの名前を指定します。
    - 3 番目の項目では、新しいテーブルの属性を定義します。
    - 4 番目の項目では、新しいテーブルのキースキーマを定義します。
    - 5 番目の項目では、Amazon DynamoDB が調整例外を返す前にコンシュームされる 1 秒あたりの厳密な一貫性読み取りと 1 秒あたりの厳密な一貫性書き込みの最大数を指定します。
    - 6 番目の項目では、セカンダリインデックスの変数を指定します。

`HTTP Listener`​ および ​`Create table`​ 操作を設定したら、Create Table の例の XML フローは次のようになります。

```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>
```

### [](#secondary-index)Issues テーブルへのセカンダリインデックスの追加

グローバルセカンダリインデックスを ​`Issues`​ テーブルに追加するには、XML の ​`<dynamodb:create-table>`​ 要素の前に変数を追加します。

次の例では、3 つのセカンダリインデックスを ​`Issues`​ テーブルに追加します。

- `CreateDateIndex`​ (​`CreateDate`​ パーティションキーと ​`IssueId`​ 並び替えキーを使用)
- `TitleIndex`​ (​`Title`​ パーティションキーと ​`IssueId`​ 並び替えキーを使用)
- `DueDateIndex`​ (​`DueDate`​ パーティションキーを使用)

XML に次の要素を含める必要があります。

- `<Projection>`​: テーブルからインデックスにコピーする属性を指定します。
    
    この例では、値 ​`ALL`​ はすべての属性がコピーされることを意味します。
    
    `<Projection>`​ 要素に設定した値に関係なく、主キー属性とインデックスキー属性は自動的にコピーされます。
- `ProvisionedThroughput`​: 読み取りおよび書き込みアクティビティのスループットをプロビジョニングします。
- `KeySchema`​: インデックスのキースキーマを指定します。

```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-logger-create)Logger コンポーネントを設定する

`Create Table`​ 操作によって生成された応答を Mule コンソールに出力するように、​`Logger`​ コンポーネントを設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、「​`logger`​」を検索します。
2. **\[Logger\]**​ コンポーネントを Studio キャンバスの ​**\[Create Table\]**​ の右にドラッグします。
3. **\[Logger\]**​ タブの ​**\[Message (メッセージ)\]**​ 項目に「​`#[payload]`​」と入力します。
    
    ![「Logger」 タブ](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-logger-props.png)
    
    Figure 6. **\[Message (メッセージ)\]**​ 項目に「​`#[payload]`​」と入力し、Mule コンソールに操作の応答を出力します。

### [](#完全な-create-table-の例の-xml)完全な Create Table の例の XML

完全な Create Table の例の XML は次のようになります。

```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>
```

### [](#プロジェクトを実行する)プロジェクトを実行する

プロジェクトを保存し、Mule アプリケーションとして実行します。

1. **Package Explorer**​ で、プロジェクト名を右クリックし、​**\[Run As (別のユーザーとして実行)\]**​ > ​**\[Mule Application (Mule アプリケーション)\]**​ をクリックします。
2. ブラウザーを開き、​`http://localhost:8081/createtable`​ URL を入力して応答を確認します。
    
    Mule コンソールに ​`Create table`​ 操作から生成された応答が表示されます。

## [](#delete-table)Amazon DynamoDB テーブルの削除

次の例は、Amazon DynamoDB Connector を使用して Amazon DynamoDB テーブルを削除する方法を示しています。

### [](#dynamodb-テーブルの削除フロー)DynamoDB テーブルの削除フロー

次のスクリーンショットは、Amazon DynamoDB テーブルを削除するための Anypoint Studio フローを示しています。

![Amazon DynamoDB テーブルを削除するための Studio フロー](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-delete-table-flow.png)

Figure 7. このサンプルフローを使用して、Amazon DynamoDB テーブルを削除します。

### [](#事前手順)事前手順

次の手順に従って、Amazon DynamoDB テーブルの削除を開始します。

1. Studio で新しい Mule プロジェクトを作成します。
2. 次のプロパティを ​`mule-artifact.properties`​ ファイルに追加して、Amazon DynamoDB ログイン情報を保持します。
    
    ```text
    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    ```
3. プロジェクトの ​`src/main/resources`​ ディレクトリに ​`mule-artifact.properties`​ ファイルを置きます。

### [](#http-リスナーを設定する)HTTP リスナーを設定する

`/deletetable`​ パスで HTTP 要求をリスンするように ​`HTTP Listener`​ を設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで「​`http`​」を検索し、​**\[Listener\]**​ 操作を選択します。
2. **\[Listener\]**​ 操作を Studio キャンバスにドラッグします。
3. **\[Listener\]**​ タブで、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (+) をクリックして、​`HTTP Listener`​ のグローバル要素設定項目にアクセスします。
4. **\[Host (ホスト)\]**​ 項目で ​`localhost`​ を選択し、​**\[OK\]**​ をクリックします。
5. **\[Listener\]**​ タブの ​**\[Path (パス)\]**​ 項目で、「​`/deletetable`​」と入力します。

### [](#delete-table-操作を設定する)Delete Table 操作を設定する

`Issues`​ テーブルを削除する ​`Delete table`​ 操作を設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、​**\[Search in Exchange (Exchange 内を検索)\]**​ をクリックして「​`amazon dynamodb`​」を検索します。
2. **\[Amazon DynamoDB Connector\]**​ を選択して ​**\[Add> (追加>)\]**​ をクリックし、​**\[Finish (完了)\]**​ をクリックします。
3. **\[Delete Table\]**​ 操作を Studio キャンバスの ​**\[Listener\]**​ の右にドラッグします。
4. フローの下の ​**\[Global Elements (グローバル要素)\]**​ リンクをクリックします。
5. [「プロパティ値のプロパティプレースホルダーの使用」](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview#property-placeholders)​の説明に従って、以前に作成したプロパティファイルを ​**\[Configuration properties (設定プロパティ)\]**​ 項目に追加します。
6. **\[Create (作成)\]**​ をクリックします。
7. **\[Connector Configuration (コネクタ設定)\]**​ を展開します。
8. **\[Amazon DynamoDB Configuration (Amazon DynamoDB 設定)\]**​ を選択し、​**\[OK\]**​ をクリックします。
9. 次の項目に入力します。
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 35%;">
<col style="width: 40%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">パラメーター</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">値</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Name (名前)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">設定名</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>delete-table-flow</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Access Key (アクセスキー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">アカウントを所有するユーザーを一意に識別する英数字のテキスト文字列</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>${config.accesskey}</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Secret Key (シークレットキー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">パスワードの役割を果たすキー。</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>${config.secretkey}</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Region Endpoint (リージョンエンドポイント)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Amazon DynamoDB クライアントに設定するリージョン</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>us-east-1</code></p>
</div></div></td>
</tr>
</tbody>
</table>
    
    対応する XML の設定は次のようになります。
    
    ```xml
    <dynamodb:config name="Amazon_DynamoDB_Configuration1" doc:name="Amazon DynamoDB Configuration" >
      <dynamodb:basic-connection
      	accessKey="${config.accesskey}"
    	  secretKey="${config.secretkey}"
      />
    </dynamodb:config>
    ```
10. **\[Test Connection (接続をテスト)\]**​ をクリックして、Mule が Amazon DynamoDB インスタンスに接続できることを確認します。
    
    - 正常に接続できた場合は、​**\[OK\]**​ をクリックして設定を保存します。
    - 接続に失敗した場合は、誤ったパラメーターを確認して修正し、もう一度テストを実行してください。
11. **\[OK\]**​ をクリックします。
12. **\[Delete table\]**​ タブで、​`Table name`​ の値を ​`Issues`​ に設定します。

### [](#configure-logger-delete)Logger コンポーネントを設定する

`Delete table`​ 操作によって生成された応答を Mule コンソールに出力するように、​`Logger`​ コンポーネントを設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、「​`logger`​」を検索します。
2. **\[Logger\]**​ コンポーネントを Studio キャンバスの ​**\[Delete Table\]**​ の右にドラッグします。
3. **\[Logger\]**​ タブで、​**\[Message (メッセージ)\]**​ 項目に「​`#[payload]`​」と入力します。

### [](#delete-table-の例の-xml)Delete Table の例の XML

Delete Table の例の XML は次のようになります。

```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>
```

### [](#プロジェクトを実行する-2)プロジェクトを実行する

プロジェクトを保存し、Mule アプリケーションとして実行します。

1. **Package Explorer**​ で、プロジェクト名を右クリックし、​**\[Run As (別のユーザーとして実行)\]**​ > ​**\[Mule Application (Mule アプリケーション)\]**​ をクリックします。
2. ブラウザーを開き、​`http://localhost:8081/deletetable`​ URL を入力して応答を確認します。
    
    Mule コンソールに ​`Delete table`​ 操作から生成された応答が表示されます。

## [](#scan-operation)Amazon DynamoDB テーブルのスキャン

次の例は、Amazon DynamoDB Connector を使用して Amazon DynamoDB テーブルをスキャンする方法を示しています。

Amazon DynamoDB Connector を使用してスキャンを実行する場合、次の考慮事項が適用されます。

- DynamoDB AWS SDK は、結果を特定のページに分割します。
    
    返される結果には 1 MB の制限が適用されます。この制限を超えた場合、残りのデータを受信するには、別のスキャンを実行する必要があります。
- 後続のスキャンを実行するには、JSON 応答の ​`LastEvaluatedKey`​ 項目の値を ​`Scan`​ 操作の Studio 設定内の ​`Exclusive start keys`​ 項目に適用します。
    
    操作でデータのすべてのページが返された場合、JSON 応答の ​`LastEvaluatedKey`​ 値は null です。

### [](#テーブルのスキャンフロー)テーブルのスキャンフロー

次のスクリーンショットは、Amazon DynamoDB テーブルをスキャンするための Anypoint Studio フローを示しています。

![Amazon DynamoDB テーブルをスキャンするための Studio フロー](/mulesoft/current/ja-jp/amazon-dynamodb-connector/1.4/_images/amazon-dynamodb-scan-flow.png)

Figure 8. このサンプルフローを使用して、Amazon DynamoDB テーブルをスキャンします。

### [](#事前手順-2)事前手順

次の手順に従って、Amazon DynamoDB テーブルのスキャンを開始します。

1. Studio で新しい Mule プロジェクトを作成します。
2. 次のプロパティを ​`mule-artifact.properties`​ ファイルに追加して、Amazon DynamoDB ログイン情報を保持します。
    
    ```text
    config.accesskey=<Access Key>
    config.secretkey=<Secret Key>
    ```
3. プロジェクトの ​`src/main/resources`​ ディレクトリに ​`mule-artifact.properties`​ ファイルを置きます。

### [](#http-リスナーを設定する-2)HTTP リスナーを設定する

`/scantable`​ パスで HTTP 要求をリスンするように ​`HTTP Listener`​ を設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで「​`http`​」を検索し、​**\[Listener\]**​ 操作を選択します。
2. **\[Listener\]**​ 操作を Studio キャンバスにドラッグします。
3. **\[Listener\]**​ タブで、​**\[Connector configuration (コネクタ設定)\]**​ 項目の横にあるプラス記号 (+) をクリックして、​`HTTP Listener`​ のグローバル要素設定項目にアクセスします。
4. **\[Host (ホスト)\]**​ 項目で ​`localhost`​ を選択し、​**\[OK\]**​ をクリックします。
5. **\[Listener\]**​ タブの ​**\[Path (パス)\]**​ 項目で、「​`/scantable`​」と入力します。

### [](#scan-操作を設定する)Scan 操作を設定する

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、​**\[Search in Exchange (Exchange 内を検索)\]**​ をクリックして「​`amazon dynamodb`​」を検索します。
2. **\[Amazon DynamoDB Connector\]**​ を選択して ​**\[Add> (追加>)\]**​ をクリックし、​**\[Finish (完了)\]**​ をクリックします。
3. **\[Scan\]**​ 操作を Studio キャンバスの ​**\[Listener\]**​ の右にドラッグします。
4. フローの下の ​**\[Global Elements (グローバル要素)\]**​ リンクをクリックします。
5. [「プロパティ値のプロパティプレースホルダーの使用」](https://docs.mulesoft.com/connectors/introduction/intro-connector-configuration-overview#property-placeholders)​の説明に従って、以前に作成したプロパティファイルを ​**\[Configuration properties (設定プロパティ)\]**​ 項目に追加します。
6. **\[Create (作成)\]**​ をクリックします。
7. **\[Connector Configuration (コネクタ設定)\]**​ を展開します。
8. **\[Amazon DynamoDB Configuration (Amazon DynamoDB 設定)\]**​ を選択し、​**\[OK\]**​ をクリックします。
9. 次の項目に入力します。
    
    <table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 35%;">
<col style="width: 40%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">パラメーター</th>
<th class="tableblock halign-left valign-top">説明</th>
<th class="tableblock halign-left valign-top">値</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Name (名前)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">設定名</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>scan-table-flow</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Access Key (アクセスキー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">アカウントを所有するユーザーを一意に識別する英数字のテキスト文字列</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>${config.accesskey}</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Secret Key (シークレットキー)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">パスワードの役割を果たすキー。</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>${config.secretkey}</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Region Endpoint (リージョンエンドポイント)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Amazon DynamoDB クライアントに設定するリージョン</p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>us-east-1</code></p>
</div></div></td>
</tr>
</tbody>
</table>
10. **\[Test Connection (接続をテスト)\]**​ をクリックして、Mule が Amazon DynamoDB インスタンスに接続できることを確認します。
    
    - 正常に接続できた場合は、​**\[OK\]**​ をクリックして設定を保存します。
    - 接続に失敗した場合は、誤ったパラメーターを確認して修正し、もう一度テストを実行してください。
11. **\[OK\]**​ をクリックします。
12. **\[Scan\]**​ タブで、​`Table name`​ の値を ​`Issues`​ に設定します。

### [](#transform-message-コンポーネントを設定する)Transform Message コンポーネントを設定する

`Scan`​ 操作の出力を Java から JSON に変更する ​`Transform Message`​ コンポーネントを設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、「​`transform`​」を検索します。
2. **\[Transform Message\]**​ コンポーネントを Studio キャンバスの ​**\[Scan\]**​ の右にドラッグします。
3. **\[Scan\]**​ 操作の ​**\[Output (出力)\]**​ セクションで、​`output/application/java`​ を ​`output/application/json`​ に変更します。

### [](#configure-logger-scan)Logger コンポーネントを設定する

`Scan`​ 操作によって生成された応答を Mule コンソールに出力するように、​`Logger`​ コンポーネントを設定します。

1. **\[Mule Palette (Mule パレット)\]**​ ビューで、「​`Logger`​」を検索します。
2. **\[Logger\]**​ コンポーネントを Studio キャンバスの ​**\[Transform\]**​ の右にドラッグします。
3. **\[Logger\]**​ タブの ​**\[Message (メッセージ)\]**​ 項目に「​`#[payload]`​」と入力します。

### [](#scan-table-の例の-xml)Scan Table の例の XML

Scan Table の例の XML は次のようになります。

```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>
```

### [](#scan-table-の例への応答)Scan Table の例への応答

`Scan`​ 操作への応答は、次のようになる可能性があります (簡潔にするため、応答の他のセクションは省略されています)。

```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"
      },
      ...
  ]
}
```

### [](#プロジェクトを実行する-3)プロジェクトを実行する

プロジェクトを保存し、Mule アプリケーションとして実行します。

1. **Package Explorer**​ で、プロジェクト名を右クリックし、​**\[Run As (別のユーザーとして実行)\]**​ > ​**\[Mule Application (Mule アプリケーション)\]**​ をクリックします。
2. ブラウザーを開き、​`http://localhost:8081/scantable`​ URL を入力して応答を確認します。
    
    Mule コンソールに ​`Scan`​ 操作から生成された応答が表示されます。

## [](#関連情報)関連情報

- [Amazon API ドキュメント](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/Welcome.html)
- [Anypoint Connector の概要](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)
- [MuleSoft ヘルプセンター](https://help.mulesoft.com)