Closed josh-chai closed 5 years ago
@josh-chai
Sorry to hear that you are running into issues. Can you post a code snippet and logs - that will help debug this further.
@cbommas Thanks for help
I have enabled logs 2018-12-22 21:57:13:519 Robot[32323:744261] Initializing AWSIoTMqttConfiguration with KeepAlive:300.000000, baseReconnectTime:1.000000,minimumConnectionTime:20.000000, maximumReconnectTime:128.000000, autoResubscribe:Enabled, lwt topic: message: 2018-12-22 21:57:13:528 Robot[32323:744261] IOTDataManager: Connecting to IoT using websocket, client id: 66382713-C875-44E7-BD0B-B4EE48492AA5 2018-12-22 21:57:13:531 Robot[32323:744261] AWSIoTMQTTClient: connecting via websocket. 2018-12-22 21:57:13:555 Robot[32323:744329] username is : ?SDK=iOS&Version=2.6.19 2018-12-22 21:57:13:555 Robot[32323:744329] Metrics collection is: Enabled 2018-12-22 21:57:13:556 Robot[32323:744329] -[AWSMQTTSession initWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetainFlag:publishRetryThrottle:] [Line 82], Thread:<NSThread: 0x600002119ac0>{number = 6, name = (null)} 2018-12-22 21:57:13:556 Robot[32323:744329] +[AWSMQTTMessage connectMessageWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetain:] [Line 66], Thread:<NSThread: 0x600002119ac0>{number = 6, name = (null)} 2018-12-22 21:57:13:556 Robot[32323:744329] Creating AWSMQTTMessage with raw data >>>>> <00044d51 54540482 012c0024 36363338 32373133 2d433837 352d3434 45372d42 4430422d 42344545 34383439 32414135 00173f53 444b3d69 4f532656 65727369 6f6e3d32 2e362e31 39> <<<<< 2018-12-22 21:57:13:560 Robot[32323:744329] Websocket is created and opened. 2018-12-22 21:57:14:007 Robot[32323:744340] [SR] NSStreamEventOpenCompleted <__NSCFInputStream: 0x60000090ac70> 2018-12-22 21:57:14:007 Robot[32323:744340] [SR] Connected 2018-12-22 21:57:14:008 Robot[32323:744340] [SR] GET /mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASI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6fEmQEsy6kbgDkXAiDPE%2Br%2BjMCS9NytBlBXoEdYP69JxP2%2FsoR4MtTzY2%2FmmMZ9ZAYWlDU90kue7kOg6DLRsKcBQtqTxazaFPp1hUdx14HzYDPdQcKIuM9gCjR9vIPZIsEq1zB2TpKJC%2FVLtUBgUy7C2p4ayc3WWgJgcpsDi64o0rvP2fesmjXRTmiX6t%2FF5QQdw6ht2f%2F6aOm%2Fw9ksGby48YBa9acAkpnki9SEXc0d3oEFOkZD7vKBFN19yPbcMkTXFEvqN1sz3fF7kQa1MwkmQIr3t3iNfsw5cqXgBm2EBsP8utoQJWvleG0%2Fie55RNglRs9qsvCeKx2Hw8XSmE9dAr2ePyue2GnxHl73h0mLb%2BJHSzwqQ2BOXJwlIkrKZ95HyKwaZk6MXsOSwiIDIRBg0kfswh4X54AU%3D&X-Amz-Signature=608c4b26430f7d59bd66244aa938984dd6bcc9e206b7aeb0be0439849802b6c3 HTTP/1.1 Host: axt718sti1q4q-ats.iot.eu-west-1.amazonaws.com Sec-WebSocket-Protocol: mqttv3.1 Sec-WebSocket-Key: gC/jzBqLbfiN6zEsxbOlxA== Sec-WebSocket-Version: 13 Upgrade: websocket Origin: https://axt718sti1q4q-ats.iot.eu-west-1.amazonaws.com Connection: Upgrade
2018-12-22 21:57:14:008 Robot[32323:744340] [SR] NSStreamEventOpenCompleted <NSCFOutputStream: 0x60000090ad90> 2018-12-22 21:57:14:941 Robot[32323:744329] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x60000090ad90> 2018-12-22 21:57:14:942 Robot[32323:745204] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x60000090ad90> 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x60000090ac70> 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] Finished reading headers { "Access-Control-Allow-Origin" = "*"; Connection = "keep-alive"; "Content-Length" = 132; "Content-Type" = "application/json"; Date = "Sat, 22 Dec 2018 13:57:15 GMT"; "access-control-expose-headers" = "x-amzn-ErrorMessage, x-amzn-RequestId, x-amzn-ErrorType, Date"; "x-amzn-ErrorType" = "ForbiddenException:"; "x-amzn-RequestId" = "8a275ac1-dfb4-bc94-4820-0787099eb805"; } 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] Request failed with response code 403 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] using _delegateDispatchQueue. 2018-12-22 21:57:15:239 Robot[32323:744340] [SR] Failing with error received bad response code from server 403 2018-12-22 21:57:15:239 Robot[32323:745208] didFailWithError: Websocket failed With Error Error Domain=AWSSRWebSocketErrorDomain Code=2132 "received bad response code from server 403" UserInfo={NSLocalizedDescription=received bad response code from server 403, HTTPResponseStatusCode=403} 2018-12-22 21:57:15:239 Robot[32323:744340] [SR] Trying to disconnect
@josh-chai
You will need to do one additional step to turn on logs and route them to the console.
AWSDDLog.sharedInstance.logLevel = .verbose
AWSDDLog.add(AWSDDTTYLogger.sharedInstance)
Can you run with this setting and post the logs here.
@cbommas Thanks for help
I have enabled logs 2018-12-22 21:57:13:519 Robot[32323:744261] Initializing AWSIoTMqttConfiguration with KeepAlive:300.000000, baseReconnectTime:1.000000,minimumConnectionTime:20.000000, maximumReconnectTime:128.000000, autoResubscribe:Enabled, lwt topic: message: 2018-12-22 21:57:13:528 Robot[32323:744261] IOTDataManager: Connecting to IoT using websocket, client id: 66382713-C875-44E7-BD0B-B4EE48492AA5 2018-12-22 21:57:13:531 Robot[32323:744261] AWSIoTMQTTClient: connecting via websocket. 2018-12-22 21:57:13:555 Robot[32323:744329] username is : ?SDK=iOS&Version=2.6.19 2018-12-22 21:57:13:555 Robot[32323:744329] Metrics collection is: Enabled 2018-12-22 21:57:13:556 Robot[32323:744329] -[AWSMQTTSession initWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetainFlag:publishRetryThrottle:] [Line 82], Thread:<NSThread: 0x600002119ac0>{number = 6, name = (null)} 2018-12-22 21:57:13:556 Robot[32323:744329] +[AWSMQTTMessage connectMessageWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetain:] [Line 66], Thread:<NSThread: 0x600002119ac0>{number = 6, name = (null)} 2018-12-22 21:57:13:556 Robot[32323:744329] Creating AWSMQTTMessage with raw data >>>>> <00044d51 54540482 012c0024 36363338 32373133 2d433837 352d3434 45372d42 4430422d 42344545 34383439 32414135 00173f53 444b3d69 4f532656 65727369 6f6e3d32 2e362e31 39> <<<<< 2018-12-22 21:57:13:560 Robot[32323:744329] Websocket is created and opened. 2018-12-22 21:57:14:007 Robot[32323:744340] [SR] NSStreamEventOpenCompleted <__NSCFInputStream: 0x60000090ac70> 2018-12-22 21:57:14:007 Robot[32323:744340] [SR] Connected 2018-12-22 21:57:14:008 Robot[32323:744340] [SR] GET /mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA3ALX2FLKBNZNQBDU%2F20181222%2Fap-southeast-1%2Fiotdata%2Faws4_request&X-Amz-Date=20181222T135713Z&X-Amz-SignedHeaders=host&X-Amz-Security-Token=AgoGb3JpZ2luEMr%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCWV1LXdlc3QtMSKAAgMnOfVA2pUgdb%2FALVgHBHis0funxvyYnfCBXcQP6WwbhgnQPLv0%2F%2Fwg9MxlOQy9Yg8mHo1iGhaoV8kVuyWkTxP6Yqg0JzBHUO4PCdWvrTPmqpByP7dpOkoCZVuOmSS3AR4wiubzZDIi1sUUw86OXZ2FoWIJI9EiNKr63lNAjOrpZGnD1YvbpyExvkk192PGx%2FBzgPRB0DOiN5H36Eggl7KOHhzpbhvedqLstTAPzqP5gxHMNQTXHehDuffMXareiSTkOW749YDkKViar7VhGNJnd55ILidi%2Bt74LUTe7FTBpnVWAETVKWLgNQGmnIsV6eEUG4JLV1CiAY8sW3yEJboqrwUIj%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FARAAGgw3NTY3MDIzOTA5OTYiDJkpPDYjEMJBTiKtMiqDBVNkxWSL1rnP2O8U9xWMGPKgn%2BBosyMx%2FBIjKnbdeq%2BgK01HNAXa6AzDshtPy%2Bv4TrrOtdxa37aWzZjvGsu5i5vb1LlsYs9%2F92f829jcJkiqUxuqjS8Qkm2%2FEHtGNQ9vujHonecqayp2TrUoxtn1%2Bq3VgK%2BUnbbg9mMs658dUxkYT3WRWkFmJAu%2FZBmu4HWTSZV3Gos12cjL%2F00h4IKMvDZpFzPkt7vhrxkecJTLg0Qpxr%2FrbSL3gWMK2udBF2mSoB4EkeivyK75KsdMEe1XSPk%2Fe021zUs7stYlEhH3eRHfKF6QySgtAlipBfMipguygu%2B%2FrLiB2TDKZ5yitKGOoZ878SEDz81MxziJud0AeQgcUSdXI97wEn99cvQCGp0b6HW6NY4pUqVJkyM%2FPCbwS7GkK9XpFx0TwrSkOS%2BEt1OAaH32r3MpBiPSVfELJspJ6fEmQEsy6kbgDkXAiDPE%2Br%2BjMCS9NytBlBXoEdYP69JxP2%2FsoR4MtTzY2%2FmmMZ9ZAYWlDU90kue7kOg6DLRsKcBQtqTxazaFPp1hUdx14HzYDPdQcKIuM9gCjR9vIPZIsEq1zB2TpKJC%2FVLtUBgUy7C2p4ayc3WWgJgcpsDi64o0rvP2fesmjXRTmiX6t%2FF5QQdw6ht2f%2F6aOm%2Fw9ksGby48YBa9acAkpnki9SEXc0d3oEFOkZD7vKBFN19yPbcMkTXFEvqN1sz3fF7kQa1MwkmQIr3t3iNfsw5cqXgBm2EBsP8utoQJWvleG0%2Fie55RNglRs9qsvCeKx2Hw8XSmE9dAr2ePyue2GnxHl73h0mLb%2BJHSzwqQ2BOXJwlIkrKZ95HyKwaZk6MXsOSwiIDIRBg0kfswh4X54AU%3D&X-Amz-Signature=608c4b26430f7d59bd66244aa938984dd6bcc9e206b7aeb0be0439849802b6c3 HTTP/1.1 Host: axt718sti1q4q-ats.iot.eu-west-1.amazonaws.com Sec-WebSocket-Protocol: mqttv3.1 Sec-WebSocket-Key: gC/jzBqLbfiN6zEsxbOlxA== Sec-WebSocket-Version: 13 Upgrade: websocket Origin: https://axt718sti1q4q-ats.iot.eu-west-1.amazonaws.com Connection: Upgrade
2018-12-22 21:57:14:008 Robot[32323:744340] [SR] NSStreamEventOpenCompleted <NSCFOutputStream: 0x60000090ad90> 2018-12-22 21:57:14:941 Robot[32323:744329] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x60000090ad90> 2018-12-22 21:57:14:942 Robot[32323:745204] [SR] NSStreamEventHasSpaceAvailable <NSCFOutputStream: 0x60000090ad90> 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] NSStreamEventHasBytesAvailable <NSCFInputStream: 0x60000090ac70> 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] Finished reading headers { "Access-Control-Allow-Origin" = "*"; Connection = "keep-alive"; "Content-Length" = 132; "Content-Type" = "application/json"; Date = "Sat, 22 Dec 2018 13:57:15 GMT"; "access-control-expose-headers" = "x-amzn-ErrorMessage, x-amzn-RequestId, x-amzn-ErrorType, Date"; "x-amzn-ErrorType" = "ForbiddenException:"; "x-amzn-RequestId" = "8a275ac1-dfb4-bc94-4820-0787099eb805"; } 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] Request failed with response code 403 2018-12-22 21:57:15:238 Robot[32323:744340] [SR] using _delegateDispatchQueue. 2018-12-22 21:57:15:239 Robot[32323:744340] [SR] Failing with error received bad response code from server 403 2018-12-22 21:57:15:239 Robot[32323:745208] didFailWithError: Websocket failed With Error Error Domain=AWSSRWebSocketErrorDomain Code=2132 "received bad response code from server 403" UserInfo={NSLocalizedDescription=received bad response code from server 403, HTTPResponseStatusCode=403} 2018-12-22 21:57:15:239 Robot[32323:744340] [SR] Trying to disconnect
@josh-chai from the log it looks like the user does not have the required policy attached to it. Can you please attach a policy to the user as follows and check if it fixes the issue:
iot = AWSIoT.default()
let identityId: String? = AWSMobileClient.sharedInstance().identityId
let attachPolicyRequest = AWSIoTAttachPolicyRequest()
attachPolicyRequest?.policyName = PolicyName
attachPolicyRequest?.target = identityId
// Attach the policy to the certificate
self.iot.attachPolicy(attachPolicyRequest!).continueWith (block: { (task) -> AnyObject? in
if let error = task.error {
print("failed: [\(error)]")
}
print("result: [\(String(describing: task.result))]")
// Connect to the AWS IoT platform
if (task.error == nil)
{
}
return nil
})
Thanks @desokroshan @cbommas We are correct connected to AWS IoT after add attach policy process
But we also use AppSync, when "Archive" will fail.
Hello @josh-chai,
Sounds like the original issue has been addressed. Unfortunately, you can't use both the AWSIOT and AWSAppSync framework in the same project. The AWSAppSync project has a slightly customized implementation of the AWSIOT code with overlapping classes, because of which the two can't be used together in the same app.
We're already tracking this as a feature request with issue #1053. Please upvote the issue. I am closing this particular issue, because it has been resolved.
State your question Develop on the Swift When using AWSMobileClient to connect IoT Pub/Sub/Shadow, only the first cognito user can success, but second and more new user both can't connecting IoT.
I have use amplify js SDK on the web frontend, try the same parameters, Cognito User Pool, Idp, Idp Auth Role, IoT. That's all success. so I check my settings was right
Which AWS Services are you utilizing? AWS IoT, Cognito & IDP, Amplify
Provide code snippets (if applicable)
Environment(please complete the following information):
Device Information (please complete the following information):
Steps to reproduce the behavior: