

Amazon Timestream for LiveAnalytics와 유사한 기능을 원하는 경우 Amazon Timestream for InfluxDB를 고려해 보세요. 간소화된 데이터 수집과 실시간 분석을 위한 10밀리초 미만의 쿼리 응답 시간을 제공합니다. [여기](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 쿼리 API에 사용할 수 있는 모든 명령의 전체 목록을 보려면 Timestream for InfluxDB [AWS CLI 명령 레퍼런스](https://docs.aws.amazon.com/cli/latest/reference/timestream-query/index.html)를 참조하세요.

 AWS CLI의 Timestream for LiveAnalytics 쓰기 API에 사용할 수 있는 모든 명령의 전체 목록을 보려면 Timestream for InfluxDB [AWS CLI 명령 레퍼런스](https://docs.aws.amazon.com/cli/latest/reference/timestream-write/index.html)를 참조하세요.

**Topics**
+ [다운로드 및 구성 AWS CLI](#Tools.CLI.DownloadingAndRunning)
+ [Timestream for LiveAnalytics와 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) 및 [CLI 구성 AWS](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) 지침을 따릅니다.

## Timestream for LiveAnalytics와 AWS CLI 함께 사용
<a name="Tools.CLI.UsingWithQLDB"></a>

명령줄 형식은 Amazon Timestream for LiveAnalytics 작업 이름과 해당 작업에 대한 파라미터 순으로 구성됩니다. 는 JSON 외에도 파라미터 값에 대한 간편 구문을 AWS CLI 지원합니다.

 `help`를 사용하여 Timestream for LiveAnalytics에서 사용 가능한 모든 명령을 나열합니다. 예제: 

```
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\"\
        }\
      }"
```