I want to troubleshoot the "SERVER_INITIATED_DISCONNECT" message that I get in AWS IoT Core.
Resolution
Manage server-initiated disconnections
You get the "SERVER_INITIATED_DISCONNECT" message because AWS IoT disconnects your clients for scheduled maintenance. AWS IoT Core performs regular maintenance to update its services and doesn't have a published maintenance schedule. It's a best practice to prepare for a disconnection. For more information, see Connect/Disconnect events and Connection duration limits.
When a device disconnects from AWS IoT Core, the service publishes a message to the MQTT topic $aws/events/presence/disconnected/clientId. For a server-initiated disconnect, the disconnectReason field shows as SERVER_INITIATED_DISCONNECT.
If you receive the "SERVER_INITIATED_DISCONNECT" message, then set the defaultLogLevel for SetV2LoggingOptions as either INFO or DEBUG.
Note: For large IoT fleets, you can incur high costs and experience high data traffic when you use INFO or DEBUG. For more information, see How do I manage the log levels of my AWS IoT logs in AWS IoT Core?
Review costs
When you reconnect to AWS IoT Core, you initiate start-up processes such as AWS IoT rules, AWS Step Functions, and Amazon DynamoDB write requests. When you reconnect after a server-initiated disconnection, AWS IoT Core continues to meter the processes and you incur process charges.
Review metrics for disconnect issues
To understand why you receive the "SERVER_INITIATED_DISCONNECT" message, use Amazon CloudWatch to upload device-side logs and analyze the disconnection. You can also use CloudWatch to review AWS IoT metrics for spikes in reconnects or connect errors. Or, use the AWS IoT Device Management connectivity metrics dashboard to check disconnect metrics and causes.
To check spikes in connect notifications, you can use customer backend performance metrics.
For more information about how to identify and troubleshoot an AWS IoT Core disconnection, see Troubleshooting device fleet disconnects.
Related information
Monitor AWS IoT using CloudWatch Logs