# Connecting to AWS IoT core with username and password

**URL:** <https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530>\
**Category:** Help Hub\
**Tags:** authentication\
**Created:** [November 21, 2024, 1:38pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530 "2024-11-21T13:38:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vittorioa](https://avatars.discourse-cdn.com/v4/letter/v/b9bd4f/32.png) [@vittorioa](https://community.postman.com/u/vittorioa)\
**Post date:** [November 21, 2024, 1:38pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/1 "2024-11-21T13:38:52Z")

</div>

I’m having trouble to connect to an MQTT end point hosted in AWS IoT Core with a custom authorizer, and I would appreciate any help.

**AWS IoT Core Setup**  
I create a simple Domain in AWS with secure policy `IoTSecurityPolicy_TLS13_1_2_2022_10` and a custom authorizer which check for username and passowrd.

I tested the custom authorizer with an https and point and postman and it works correctly.

**Postman setup**  
I’m simply using the MQTT request with my AWS endpoint and the mqtts protocols (since AWS uses TLS), as follow:

 ![Screen Shot 2024-11-21 at 8.24.07 AM](https://us1.discourse-cdn.com/getpostman/original/3X/d/5/d5a3990797451383f970333523857a0064d1d191.png)

**Result**  
I’m seeing the following:

- Postman after 30 seconds, report. that it is disconnected to the broker.
- The authorizer is _not_ invoked. Which confirms that the connection was not accepted

**Question**

- I see from the documentation that AWS for TLS requires the ALPN protocol to `mqtt`. Is this the issue ? how can I check it ?
- Does anyone know how I can get this to work correctly ? please note that _I need to use old devices with AWS IoT_ and I can not change the behaviour on the device.

---

<div class="post-metadata">

**Author:** ![docking-module-admin](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/docking-module-admin/32/27595_2.png) [@docking-module-admin](https://community.postman.com/u/docking-module-admin)\
**Post date:** [November 21, 2024, 3:23pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/2 "2024-11-21T15:23:00Z")

</div>

Hey @vittorioa could you confirm the port that you’re trying to connect to? I know that was it core exposes different ports for different auth and ALPN. I see that you’re using custom auth so based on [this](https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html) I’m assuming port 443, but am not seeing that in your screenshot?

---

<div class="post-metadata">

**Author:** ![vittorioa](https://avatars.discourse-cdn.com/v4/letter/v/b9bd4f/32.png) [@vittorioa](https://community.postman.com/u/vittorioa)\
**Post date:** [November 21, 2024, 4:26pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/3 "2024-11-21T16:26:23Z")

</div>

Thank you Jonathan for your reply. I tested with port 443 and 8883 and the result is the same. Here is the configuration of the AWS Domain, which determines the protocol:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/b/0b162c0a707a6cc5db2abbde7cc0c879292c634d.png)  
and here are the settings:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/e/5/e54ab6b15757fa4b0b29dd5b7c09e7890eabaa09.jpeg)  
but the result is allways “Disconnected from the Broker”:  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/4/a4882a93fc6210a392c625185f07f169e68d389e.jpeg)

It appears to me that it doesn’t connect at all, because I know for sure that the authorizer is not invoked.

Any suggestion is welcome !

---

<div class="post-metadata">

**Author:** ![vittorioa](https://avatars.discourse-cdn.com/v4/letter/v/b9bd4f/32.png) [@vittorioa](https://community.postman.com/u/vittorioa)\
**Post date:** [November 21, 2024, 4:46pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/4 "2024-11-21T16:46:29Z")

</div>

@docking-module-admin here is more information regarding the port:

- when I use port 443 as in the picture above the postman times out and reports the error `Disconnected from Broker`
- when I used port 8443 as follow `mqtts://.......-ats.iot.us-east-1.amazonaws.com:8443` postman return immediately with an error `An error occurred: Client network socket disconnected before secure TLS connection was established`
- when I used port 8883 as follow `mqtts://.......-ats.iot.us-east-1.amazonaws.com:8883` postman return immediately with an error `An error occurred: Client network socket disconnected before secure TLS connection was established`

I’m not able to get _any_ log on the AWS side. It appears to me that the TLS connection is rejected. Do you understand why ?

---

<div class="post-metadata">

**Author:** ![docking-module-admin](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/docking-module-admin/32/27595_2.png) [@docking-module-admin](https://community.postman.com/u/docking-module-admin)\
**Post date:** [November 21, 2024, 5:43pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/5 "2024-11-21T17:43:17Z")

</div>

@vittorioa thanks for the update! Can you confirm if your domain configuration looks like this?

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/4/f4a1e77a4714e7bd2142215d966499cec187de25.png)

---

<div class="post-metadata">

**Author:** ![vittorioa](https://avatars.discourse-cdn.com/v4/letter/v/b9bd4f/32.png) [@vittorioa](https://community.postman.com/u/vittorioa)\
**Post date:** [November 21, 2024, 5:46pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/6 "2024-11-21T17:46:19Z")

</div>

Yes, correct. It is enabled.

---

<div class="post-metadata">

**Author:** ![vittorioa](https://avatars.discourse-cdn.com/v4/letter/v/b9bd4f/32.png) [@vittorioa](https://community.postman.com/u/vittorioa)\
**Post date:** [November 21, 2024, 8:53pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/7 "2024-11-21T20:53:56Z")

</div>

For anyone getting to this topic: I was not able to use with postman, however this simple nodejs application was able to talk to the AWS IoT endpoint with a custom authorizer using username and password on TLS MQTT:

```auto
const mqtt = require("mqtt");

const endPoint= " ******* -ats.iot.REGION.amazonaws.com"; 
const topic = 'test';
const options = {
    protocolId: 'MQTT',
    protocolVersion: 5,
    username: " *******",
    password: " *******"
}

console.log('building client');
const client = mqtt.connect(
    'mqtts://' +endPoint+ ':8883',
    options
);

client.on('connect', function () {
    console.log("connected !");
    client.subscribe(topic, function (err) {
    console.log('subscribe to: ' + topic );
        if (err) {
            console.log('subscribe error: ' + err);
        };
    });
});

client.on('message', (topic, message) => {
    console.log('message received: subscription topic: ' + topic + ' topic: ' + topic + ' message: ' + message.toString());
  });

setInterval(function () {
    var message = `{ "time":${(new Date()).getTime()}}`
    console.log('publish: topic: ' + topic + ' message: ' + message);
    client.publish(topic, message);
}, 5000);

```

---

<div class="post-metadata">

**Author:** ![docking-module-admin](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/docking-module-admin/32/27595_2.png) [@docking-module-admin](https://community.postman.com/u/docking-module-admin)\
**Post date:** [November 22, 2024, 5:19pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/8 "2024-11-22T17:19:02Z")

</div>

@vittorioa based on the configuration, if you haven’t already would you be able to upload certificates for this endpoint? Thank you for sharing the alternative solution!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 22, 2024, 5:19pm UTC](https://community.postman.com/t/connecting-to-aws-iot-core-with-username-and-password/71530/9 "2024-12-22T17:19:45Z")

</div>

Closed on December 22, 2024, 5:19pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
