# AWS Elastic Beanstalk インポート統合

AWS Elastic BeanstalkとTreasure Dataを組み合わせることで、フロントエンドとバックエンドの両方のシステムにおいて、即座にスケーラビリティを実現できます。

# 前提条件

- Treasure Dataの基本知識
- AWS Elastic Beanstalkの基本知識


# Treasure Agentのインストール

以下の手順に従って、Treasure Agent(td-agent)ストリーミングデータコレクターをアプリケーションにインストールします。

## td-agentとは?

Treasure DataのTd-agentは、AWS Elastic Beanstalkコンテナ上でTreasure Dataを使用するために必要な分散ログコレクターです。td-agentを使用して、AWS Elastic BeanstalkアプリケーションからTreasure Dataのクラウドデータウェアハウスにログをインポートします。

## インストール

コンテナ内にtd-agentをインストールするためのボイラープレートアプリケーションは、次のリポジトリで利用できます:

- [treasure-data/elastic-beanstalk-td-agent](https://github.com/treasure-data/elastic-beanstalk-td-agent)


### .ebextensionsスクリプトのインストール

以下の例に示すように、GitHubから2つのファイルをダウンロードし、.ebextensionsディレクトリに配置します。


```bash
$ cd $YOUR\_REPO
$ mkdir -p .ebextensions
$ wget -O.ebextensions/0-td-agent-gen-config.config '<https://raw.github.com/treasure-data/elastic-beanstalk-td-agent/master/.ebextensions/0-td-agent-gen-config.config>'
$ wget -O.ebextensions/1-td-agent-install.config '<https://raw.github.com/treasure-data/elastic-beanstalk-td-agent/master/.ebextensions/1-td-agent-install.config>'
```

### APIキーの設定

次に、設定ファイル内の適切な場所にAPIキーを配置します。


```bash
$ td apikey:show
$ emacs .ebextensions/0-td-agent-gen-config.config
```

### デプロイ

最後に、変更を本番環境にデプロイします。


```bash
$ git add .ebextensions/0-td-agent-gen-config.config
$ git add .ebextensions/1-td-agent-install.config
$ git commit -a -m 'custom extensions to install td-agent'
$ git aws.push
```

## データアップロードの確認

curlコマンドを発行して、ローカルシステムからTreasure Dataにログをインポートできます。


```bash
$ curl -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/td.testdb.www\_access
$ curl -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/td.testdb.www\_access
$ curl -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/td.testdb.www\_access
$ curl -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/td.testdb.www\_access
$ curl -X POST -d 'json={"action":"login","user":2}' http://localhost:8888/td.testdb.www\_access
```

数分後(通常は約5分)、次のコマンドを発行して、データがクラウドにアップロードされたことを確認できます。カウントがゼロより大きい場合、データのアップロードは成功しています。


```bash
$ td tables testdb
+----------+-------------------------+------+-------+----------------+
| Database | Table | Type | Count | Schema |
+----------+-------------------------+------+-------+----------------+
| testdb | www\_access | log | 5 | |
+----------+-------------------------+------+-------+----------------+
```

# アプリケーションからのデータインポート

これで、td-agent経由でアプリケーションからTreasure Dataにデータをインポートする準備が整いました。アプリケーションの言語に適したロガーを選択してください。

**Supported Languages**

- [Ruby](/ja/int/ruby-apps-import-integration) or [Rails](/ja/int/rails-apps-import-integration)
- [Java](/ja/int/java-apps-import-integration)
- [Perl](/ja/int/perl-apps-import-integration)
- [Python](/ja/int/python-apps-import-integration)
- [PHP](/ja/int/php-apps-import-integration)
- [Scala](/ja/int/scala-apps-import-integration)
- [Node.js](/ja/int/node-js-apps-import-integration)