AWS IoT 에서 아래와 같이 Detail 한 CloudWatch Log를 보려면, CLI로 Log v2를 적용해야 합니다.
관련링크: https://docs.aws.amazon.com/iot/latest/developerguide/cwl-format.html
{
"timestamp": "2017-08-10 15:37:23.476",
"logLevel": "INFO",
"traceId": "20b23f3f-d7f1-feae-169f-82263394fbdb",
"accountId": "123456789012",
"status": "Success",
"eventType": "Connect",
"protocol": "MQTT",
"clientId": "abf27092886e49a8a5c1922749736453",
"principalId": "145179c40e2219e18a909d896a5340b74cf97a39641beec2fc3eeafc5a932167",
"sourceIp": "205.251.233.181",
"sourcePort": 13490
}
|
사전에 IAM Role을 생성해야 합니다.
관련링크: https://docs.aws.amazon.com/iot/latest/developerguide/configure-logging.html
Role policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:PutMetricFilter",
"logs:PutRetentionPolicy"
],
"Resource": [
"*"
]
}
]
}
Trust policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "iot.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
CLI 는 다음과 같이 수행할 수 있습니다.
aws iot set-v2-logging-options --role-arn {logging-role-arn} --default-log-level {log-level} --region {region}
관련링크: https://docs.aws.amazon.com/iot/latest/developerguide/configure-logging.html#fine-logging-cli
현재 설정된 IoT V2 Log 정보는 다음과 같이 확인할 수 있습니다.
aws iot list-v2-logging-levels
해당 CLI에 대한 정보는 다음 링크에서 더 확인 가능합니다.
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iot/set-v2-logging-options.html
설정된 IoT V2 Log는 CloudWatch Log Group에서 "AWSIotLogsV2" 를 검색하여서 확인할 수 있습니다.
관련링크: https://docs.aws.amazon.com/iot/latest/developerguide/cloud-watch-logs.html