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}