AWS IoT
开发人员指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

诊断规则问题

CloudWatch Logs 是您对规则所存在的问题进行调试的最佳位置。为 AWS IoT 启用 CloudWatch Logs 后,您可了解哪些规则被触发以及操作是成功还是失败。您还可以了解 WHERE 子句条件是否匹配。

最常见的规则问题是授权问题。可通过日志了解您的角色是否获得对资源执行 AssumeRole 操作所需的权限。下面是一个精细日志记录功能生成的示例日志:

{ "timestamp": "2017-12-09 22:49:17.954", "logLevel": "ERROR", "traceId": "ff563525-6469-506a-e141-78d40375fc4e", "accountId": "123456789012", "status": "Failure", "eventType": "RuleExecution", "clientId": "iotconsole-123456789012-3", "topicName": "test-topic", "ruleName": "rule1", "ruleAction": "DynamoAction", "resources": { "ItemHashKeyField": "id", "Table": "trashbin", "Operation": "Insert", "ItemHashKeyValue": "id", "IsPayloadJSON": "true" }, "principalId": "ABCDEFG1234567ABCD890:outis", "details": "User: arn:aws:sts::123456789012:assumed-role/dynamo-testbin/5aUMInJH is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-east-1:123456789012:table/testbin (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: AccessDeniedException; Request ID: AKQJ987654321AKQJ123456789AKQJ987654321AKQJ987654321)" }

下面是一个全局日志记录功能生成的类似示例日志:

2017-12-09 22:49:17.954 TRACEID:ff562535-6964-506a-e141-78d40375fc4e PRINCIPALID:ABCDEFG1234567ABCD890:outis [ERROR] EVENT:DynamoActionFailure TOPICNAME:test-topic CLIENTID:iotconsole-123456789012-3 MESSAGE:Dynamo Insert record failed. The error received was User: arn:aws:sts::123456789012:assumed-role/dynamo-testbin/5aUMInJI is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-east-1:123456789012:table/testbin (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: AccessDeniedException; Request ID: AKQJ987654321AKQJ987654321AKQJ987654321AKQJ987654321). Message arrived on: test-topic, Action: dynamo, Table: trashbin, HashKeyField: id, HashKeyValue: id, RangeKeyField: None, RangeKeyValue: 123456789012 No newer events found at the moment. Retry.

有关更多信息,请参阅 查看日志

外部服务由最终用户控制。在执行规则之前,请确保为外部服务设置了足够的吞吐量和容量单位。