-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AWS MQTT3 Websockets Connection Closed Unexpectedly #586
Comments
The most likely issue is a permission problem (missing or mismatched iot connect permission) on the cognito-sourced credentials. Beyond that, once it's working, you don't want to stuff session credentials in a static provider. You could use https://github.com/awslabs/aws-crt-java/blob/main/src/main/java/software/amazon/awssdk/crt/auth/credentials/DelegateCredentialsProvider.java to adapt the cognito sourcing or you could use the CRT's cognito provider: https://github.com/awslabs/aws-crt-java/blob/main/src/main/java/software/amazon/awssdk/crt/auth/credentials/CognitoCredentialsProvider.java |
Also, if you enable and attach SDK logs, we may be able to get a more detailed diagnosis. |
I think it might not be connected with permissions. Look at this code - I'm taking credentials from cognito and I'm querying HTTP shadow endpoint ( BTW I'm aweare of |
I'm attaching |
Another thing: when I'm using Look at line |
The permissions needed to perform an http request to the shadow service and the permissions needed to use IoT Core's mqtt broker are very different. I looked at the logs. The connection is successfully established. The signed websocket handshake upgrade succeeds. The remote hosts closes the connection immediately after the CONNECT packet was sent. I know of no other possible explanation then a permissions problem. What is the policy associated with the cognito query? Have you tried loosening it to allow everything as a sanity check? |
I'm not an owner of this MQTT endpoint so I cannot loosen anything :(. I know the other team uses flutter/dart to connect to AWS IoT and they are attaching policy. Is it possible with MQTT? print(await Cognito.initialize());
if (!await Cognito.isSignedIn()) {
print(await Cognito.signIn(dotenv.env['USERNAME'], dotenv.env['PASSWORD']));
}
print(await Cognito.getIdentityId());
var device = AWSIotDevice(
endpoint: dotenv.env['ENDPOINT'],
clientId: dotenv.env['CLIENT_ID'],
);
await device.attachPolicy(
identityId: await Cognito.getIdentityId(),
policyName: dotenv.env['POLICY_NAME'],
);
await device.connect(); |
The permissions associated with the sourced credentials come from your cognito identity pool configuration, which is a resource under your control |
Thanks for the help! Now everything is clear :)! |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the bug
I'm trying to connect to AWS MQTT3 via websockets with authentication from Cognito, but I'm getting
Caused by: software.amazon.awssdk.crt.mqtt.MqttException: The connection was closed unexpectedly.
. What might be the problem?This is my method for getting
GetCredentialsForIdentityResponse
After this I'm using
GetCredentialsForIdentityResponse
to obtainMqttClientConnection
:and then when I'm trying to connect I'm getting previously mentioned error:
Expected Behavior
Connect to MQTT via websockets
Current Behavior
Caused by: software.amazon.awssdk.crt.mqtt.MqttException: The connection was closed unexpectedly
Reproduction Steps
Repo: https://github.com/magx2/salus/blob/master/app/src/main/java/pl/grzeslowski/WsMqtt.java#L21
Possible Solution
No response
Additional Information/Context
No response
SDK version used
software.amazon.awssdk.iotdevicesdk:aws-iot-device-sdk:1.20.7
Environment details (OS name and version, etc.)
Windows 11
The text was updated successfully, but these errors were encountered: