

Amazon Timestream for LiveAnalytics に類似した機能をご希望の場合は Amazon Timestream for InfluxDB をご検討ください。リアルタイム分析に適した、シンプルなデータインジェストと 1 桁ミリ秒のクエリ応答時間を特徴としています。詳細については、[こちら](https://docs.aws.amazon.com//timestream/latest/developerguide/timestream-for-influxdb.html)を参照してください。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# を使用した LiveAnalytics 用 Amazon Timestream へのアクセス AWS CLI
<a name="Tools.CLI"></a>

 AWS Command Line Interface (AWS CLI) を使用して、コマンドラインから複数の AWS サービスを制御し、スクリプトを使用して自動化できます。アドホックオペレーション AWS CLI には を使用できます。また、ユーティリティスクリプト内に Amazon Timestream for LiveAnalytics オペレーションを埋め込むときにも使用できます。

 Timestream for LiveAnalytics AWS CLI で を使用する前に、プログラムによるアクセスを設定する必要があります。詳細については、「[プログラマチックアクセス権を付与する](accessing.md#programmatic-access)」を参照してください。

 AWS CLIで Timestream for LiveAnalytics Query API 向けに使用できるすべてのコマンドのリストについては、「[AWS CLI Command Reference](https://docs.aws.amazon.com/cli/latest/reference/timestream-query/index.html)」を参照してください。

 AWS CLIで Timestream for LiveAnalytics Write API 向けに使用できるすべてのコマンドのリストについては、「[AWS CLI コマンドリファレンス](https://docs.aws.amazon.com/cli/latest/reference/timestream-write/index.html)」を参照してください。

**Topics**
+ [のダウンロードと設定 AWS CLI](#Tools.CLI.DownloadingAndRunning)
+ [LiveAnalytics での Timestream AWS CLI での の使用](#Tools.CLI.UsingWithQLDB)

## のダウンロードと設定 AWS CLI
<a name="Tools.CLI.DownloadingAndRunning"></a>

は Windows、macOS、または Linux で AWS CLI 実行されます。ダウンロード、インストールおよび設定するには次の手順に従います。

1. [http://aws.amazon.com/cli](https://aws.amazon.com/cli) AWS CLI で をダウンロードします。

1. 「 *AWS Command Line Interface ユーザーガイド*[」の AWS 「 CLI のインストール](https://docs.aws.amazon.com/cli/latest/userguide/installing.html)」および[AWS 「 CLI の設定](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html)」の手順に従います。

## LiveAnalytics での Timestream AWS CLI での の使用
<a name="Tools.CLI.UsingWithQLDB"></a>

コマンドラインの形式は、Amazon Timestream for LiveAnalytics オペレーション名の後に、そのオペレーション用のパラメータが続く形式です。は、JSON に加えてパラメータ値の短縮構文 AWS CLI をサポートしています。

 Timestream for LiveAnalytics で使用可能なすべてのコマンドを一覧表示するには、`help` を使用します。例えば、次のようになります。

```
aws timestream-write help
```

```
aws timestream-query help
```

 また `help` を使用して、特定コマンドを記述したり、その用法の詳細を確認したりすることもできます。

```
aws timestream-write create-database help
```

 例えば、データベースを作成するには: 

```
aws timestream-write create-database --database-name myFirstDatabase
```

 マグネティックストアの書き込みを有効にしてテーブルを作成するには: 

```
aws timestream-write create-table \
--database-name metricsdb \
--table-name metrics \
--magnetic-store-write-properties "{\"EnableMagneticStoreWrites\": true}"
```

単一メジャーレコードを使用してデータを書き込むには:

```
aws timestream-write write-records \
--database-name metricsdb \
--table-name metrics \
--common-attributes "{\"Dimensions\":[{\"Name\":\"asset_id\", \"Value\":\"100\"}], \"Time\":\"1631051324000\",\"TimeUnit\":\"MILLISECONDS\"}" \
--records "[{\"MeasureName\":\"temperature\", \"MeasureValueType\":\"DOUBLE\",\"MeasureValue\":\"30\"},{\"MeasureName\":\"windspeed\", \"MeasureValueType\":\"DOUBLE\",\"MeasureValue\":\"7\"},{\"MeasureName\":\"humidity\", \"MeasureValueType\":\"DOUBLE\",\"MeasureValue\":\"15\"},{\"MeasureName\":\"brightness\", \"MeasureValueType\":\"DOUBLE\",\"MeasureValue\":\"17\"}]"
```

マルチメジャーレコードを使用してデータを書き込むには:

```
# wide model helper method to create Multi-measure records
function ingest_multi_measure_records {
  epoch=`date +%s`
  epoch+=$i

  # multi-measure records
  aws timestream-write write-records \
  --database-name $src_db_wide \
  --table-name $src_tbl_wide \
  --common-attributes "{\"Dimensions\":[{\"Name\":\"device_id\", \
              \"Value\":\"12345678\"},\
            {\"Name\":\"device_type\", \"Value\":\"iPhone\"}, \
            {\"Name\":\"os_version\", \"Value\":\"14.8\"}, \
            {\"Name\":\"region\", \"Value\":\"us-east-1\"} ], \
            \"Time\":\"$epoch\",\"TimeUnit\":\"MILLISECONDS\"}" \
--records "[{\"MeasureName\":\"video_metrics\", \"MeasureValueType\":\"MULTI\", \
  \"MeasureValues\": \
  [{\"Name\":\"video_startup_time\",\"Value\":\"0\",\"Type\":\"BIGINT\"}, \
  {\"Name\":\"rebuffering_ratio\",\"Value\":\"0.5\",\"Type\":\"DOUBLE\"}, \
  {\"Name\":\"video_playback_failures\",\"Value\":\"0\",\"Type\":\"BIGINT\"}, \
  {\"Name\":\"average_frame_rate\",\"Value\":\"0.5\",\"Type\":\"DOUBLE\"}]}]" \
--endpoint-url $ingest_endpoint \
  --region  $region
}

# create 5 records
for i in {100..105};
  do ingest_multi_measure_records $i;
done
```

テーブルに対してクエリを実行するには: 

```
aws timestream-query query \
--query-string "SELECT time, device_id, device_type, os_version, 
region, video_startup_time, rebuffering_ratio, video_playback_failures, \
average_frame_rate \
FROM metricsdb.metrics \
where time >= ago (15m)"
```

スケジュールされたクエリを作成するには: 

```
aws timestream-query create-scheduled-query \
  --name scheduled_query_name \
  --query-string "select bin(time, 1m) as time, \
          avg(measure_value::double) as avg_cpu, min(measure_value::double) as min_cpu, region \
          from $src_db.$src_tbl where measure_name = 'cpu' \
          and time BETWEEN @scheduled_runtime - (interval '5' minute)  AND @scheduled_runtime \
          group by region, bin(time, 1m)" \
  --schedule-configuration "{\"ScheduleExpression\":\"$cron_exp\"}" \
  --notification-configuration "{\"SnsConfiguration\":{\"TopicArn\":\"$sns_topic_arn\"}}" \
  --scheduled-query-execution-role-arn "arn:aws:iam::452360119086:role/TimestreamSQExecutionRole" \
  --target-configuration "{\"TimestreamConfiguration\":{\
          \"DatabaseName\": \"$dest_db\",\
          \"TableName\": \"$dest_tbl\",\
          \"TimeColumn\":\"time\",\
          \"DimensionMappings\":[{\
            \"Name\": \"region\", \"DimensionValueType\": \"VARCHAR\"
          }],\
          \"MultiMeasureMappings\":{\
            \"TargetMultiMeasureName\": \"mma_name\",
            \"MultiMeasureAttributeMappings\":[{\
              \"SourceColumn\": \"avg_cpu\", \"MeasureValueType\": \"DOUBLE\", \"TargetMultiMeasureAttributeName\": \"target_avg_cpu\"
            },\
            { \
              \"SourceColumn\": \"min_cpu\", \"MeasureValueType\": \"DOUBLE\", \"TargetMultiMeasureAttributeName\": \"target_min_cpu\"
            }] \
          }\
          }}" \
  --error-report-configuration "{\"S3Configuration\": {\
        \"BucketName\": \"$s3_err_bucket\",\
        \"ObjectKeyPrefix\": \"scherrors\",\
        \"EncryptionOption\": \"SSE_S3\"\
        }\
      }"
```