{Timestream}Accessing Amazon Timestream Using the AWS CLI

前提:
aws-cli/2.2.33
aws cli version 1の場合、エラー

export AWS_DEFAULT_REGION=us-east-1

-- 1. データベース作成

aws timestream-write create-database \
--database-name test

-- 2. テーブル作成

aws timestream-write create-table \
--database-name test \
--table-name tab1 \
--retention-properties "MemoryStoreRetentionPeriodInHours=1,MagneticStoreRetentionPeriodInDays=1"


-- 3. データベース一覧
aws timestream-write list-databases

aws timestream-write describe-database \
--database-name test

 

-- 4. テーブル一覧
aws timestream-write list-tables

aws timestream-write describe-table \
--database-name test \
--table-name tab1


-- 5. データ追加
※Timeはエポックタイムで現実的時刻の必要あり


vim a.json

[
{
"Dimensions": [
{"Name": "region", "Value": "us-east-1"},
{"Name": "az", "Value": "az1"},
{"Name": "hostname", "Value": "host1"}
],
"MeasureName": "cpu_utilization",
"MeasureValue": "13.5",
"MeasureValueType": "DOUBLE",
"Time": "1630396170",
"TimeUnit": "SECONDS"
},
{
"Dimensions": [
{"Name": "region", "Value": "us-east-1"},
{"Name": "az", "Value": "az1"},
{"Name": "hostname", "Value": "host1"}
],
"MeasureName": "memory_utilization",
"MeasureValue": "40",
"MeasureValueType": "DOUBLE",
"Time": "1630396170",
"TimeUnit": "SECONDS"
}
]

aws timestream-write write-records \
--database-name test \
--table-name tab1 \
--records file://a.json

 


-- 6. データクエリ

aws timestream-query query \
--query-string "select * from test.tab1 order by time desc limit 10"

aws timestream-query query \
--query-string "describe test.tab1"


aws timestream-query query \
--query-string "select bin(time,10s) binned_time,avg(measure_value::double) avg,count(*) cnt
from test.tab1
where measure_name = 'cpu_utilization'
group by bin(time,10s)
order by bin(time,10s)"


※::dobuleは省略できない。

-- 7. テーブル削除

aws timestream-write delete-table \
--database-name test \
--table-name tab1

-- 8. データベース削除

aws timestream-write delete-database \
--database-name test