<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Xdugu on Medium]]></title>
        <description><![CDATA[Stories by Xdugu on Medium]]></description>
        <link>https://medium.com/@xdugu2007?source=rss-805db27c12d3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kEbcMJ28Cy9lYOJi</url>
            <title>Stories by Xdugu on Medium</title>
            <link>https://medium.com/@xdugu2007?source=rss-805db27c12d3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:28:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xdugu2007/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AWS IoT Core device connection checklist (Web browser)]]></title>
            <link>https://medium.com/@xdugu2007/aws-iot-core-device-connection-checklist-web-browser-03eb81d32910?source=rss-805db27c12d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/03eb81d32910</guid>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-iot]]></category>
            <category><![CDATA[aws-iam]]></category>
            <dc:creator><![CDATA[Xdugu]]></dc:creator>
            <pubDate>Wed, 02 Sep 2026 17:12:57 GMT</pubDate>
            <atom:updated>2026-09-02T17:14:21.691Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@xdugu2007/signing-a-url-request-to-connect-to-aws-iot-mqtt-over-web-sockets-e2af8dc4f23b?sharedUserId=xdugu2007">In my previous post</a>, I documented how to sign a url and connect to AWS IoT through a browser. In this article I shall list a checklist of permissions that need to be setup to enable successful connection and communication. Use this as a checklist to ensure all permissions are in place when performing a connection</p><blockquote>Please note the following assumes default connection through AWS services (Signature V4) rather than using a custom authoriser (an article for another day)</blockquote><h3>Use case</h3><p>As a authenticated customer using a browser, I want to connect to AWS IoT Core so I can send and read messages to my smart devices</p><h3>AWS Services</h3><p><strong>Cognito (User &amp; Identity pools) — </strong>Identifies and authenticates users</p><ol><li>Ensure you have created a User pool (This is how the user can authenticate themselves e.g. with username and password)</li><li>Ensure you have at least one App client in the user pool</li><li>Ensure you have created an Identity Pool</li><li>Ensure User pool is linked to the created Identity Pool as an identity provider. You can choose to use other Identity providers e.g. Google, Facebook etc, in which case, you can skip steps 1 and 2</li><li>Ensure the identity pool has “Authenticated Access” enabled with an authenticated role</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YXdyNOh-OymPpCsBashVSw.png" /><figcaption>Screenshot of selected identity pool</figcaption></figure><p>7. Ensure you have created at least one verified user account in user pool</p><p>8. Ensure the user has signed in at least once<strong> after</strong> linking to Identity pool</p><p>9. Check the “Identity browser” for your identity pool and verify at least one identity is visible. <strong>Keep note of the identity id to be used later!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PLLIqBsazRKXpAqOcnyNQ.png" /><figcaption>Screenshot of identity browser showing the id of user signed in</figcaption></figure><p><strong>Identity and Access Management (IAM)</strong></p><ol><li>Ensure the authenticated role attached to the identity pool has the minimum IoT permission to connect, subscribe, publish and receive messages. To ensure the signed in user can get credentials to sign MQTT connection request, the <strong><em>cognito-identity:GetCredentialsForIdentity</em></strong> policy is also required</li></ol><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;cognito-identity:GetCredentialsForIdentity&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;*&quot;<br>            ]<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iot:Connect&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:iot:REGION:ACCOUNT_ID:client/*&quot;<br>            ]<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iot:Publish&quot;,<br>                &quot;iot:Receive&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:iot:REGION:ACCOUNT_ID:topic/*&quot;<br>            ]<br>        },<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: [<br>                &quot;iot:Subscribe&quot;<br>            ],<br>            &quot;Resource&quot;: [<br>                &quot;arn:aws:iot:REGION:ACCOUNT_ID:topicfilter/*&quot;<br>            ]<br>        }<br>    ]<br>}</pre><blockquote>Please note that these are broad permissions for testing and should be further restricted in prod. For example the policy to allow “subscribe” must be restricted to the actual message or message pattern to subscribe to. The example above gives access to subscribe to <strong>ANY</strong> topic</blockquote><p><strong>IoT Core — </strong>MQTT broker that manages connection.</p><p>IoT core manages its own policy which must be linked to the Identity pool user. Missing this step will mean connection is refused for authentication reasons.</p><ol><li>Find policies in IoT Core by navigating to Security &gt; Policies</li><li>Ensure a policy exists or create one specifically for this use case. Below is the minimum</li></ol><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Connect&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:iot:REGION:ACCOUNT_ID:*&quot;<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Publish&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:iot:REGION:ACCOUNT_ID:*&quot;<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Receive&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:iot:REGION:ACCOUNT_ID:*&quot;<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iot:Subscribe&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:iot:REGION:ACCOUNT_ID:*&quot;<br>    }<br>}</pre><p>3. Check the “Targets” Tab for the policy. This explicitly states which “users” have the permission for the policy above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jyhF9ygKltlU_yQDp1xxAg.png" /><figcaption>Screenshot of a policy with the “targets” tab showing the linked cognito identities</figcaption></figure><p>4. Ensure the identity id from <strong>“Cognito” section point 9</strong> is in the list. If not, it is not currently possible to add the id through the GUI. Use the cloud shell or you command line and enter this command:</p><pre>aws iot attach-policy \<br>    --policy-name &quot;YourIoTPolicyName&quot; \<br>    --target &quot;Identity id from identity browser e.g. us-east-1:12345678...&quot;</pre><p>This step above is tricky because every new signed in user must have their ids attached to this policy to be able to connect. The recommended best practice is to create a lambda function accessed through api gateway which the user can call. The lambda function then attaches the user’s identity to the policy.</p><p>If all the above steps are followed, you have the necessary permissions to connect and use IoT Core service.</p><blockquote>Random Quote</blockquote><blockquote>Life is more fun finding purpose</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03eb81d32910" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Signing a URL request to connect to AWS IoT(MQTT over Web sockets)]]></title>
            <link>https://medium.com/@xdugu2007/signing-a-url-request-to-connect-to-aws-iot-mqtt-over-web-sockets-e2af8dc4f23b?source=rss-805db27c12d3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2af8dc4f23b</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[mqtt]]></category>
            <category><![CDATA[code-signing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Xdugu]]></dc:creator>
            <pubDate>Tue, 01 Sep 2026 20:04:43 GMT</pubDate>
            <atom:updated>2026-09-01T20:09:03.160Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I spent countless hours figuring this out and hoped this article might be useful for someone else in the future, if not my future self.</blockquote><p>I wanted to create a Web app (Browser-based) to connect to AWS IoT Core, using MQTT protocol to subscribe, publish and receive messages. My plan was to control and read data from smart devices also connected to the MQTT broker. Since web browsers don’t support<a href="https://stackoverflow.com/questions/78217002/what-makes-mqtt-a-raw-tcp-connection-that-we-cant-run-it-in-the-browser"> “raw” TCP for security reasons</a>, the websocket protocol is used to wrap the MQTT protocol. This connection request requires a signed url; this part took a while to figure out.</p><p>The standard way to sign a request for AWS services is to use a library like <strong>@smithy/signature-v4</strong> or<strong> @aws-sdk/signature-v4</strong>, passing in the <strong><em>accessKeyId</em></strong>, <strong><em>secretAccessKey</em></strong> and<strong> <em>sessionToken</em></strong>. This info is used to sign the request and a url is returned to request a connection with. However, this standard method will not work with connecting to IoT Core.</p><p>Thanks to <a href="https://github.com/aws-amplify/amplify-flutter/issues/6079">this issue</a> reported on Github, I figured out that for IoT Core, the session token cannot be included in signing the request. <strong>Rather, it must be included after</strong>. There is no AWS documentation that directly specifies this. I only found this difference by comparing an old aws-amplify project I was using previously which had a custom signer.</p><p>By not including the session token and adding it after signing, the connection works. Here is a code snippet:</p><pre>import { Sha256 } from &quot;@aws-crypto/sha256-browser&quot;;<br>import { SignatureV4 } from &quot;@aws-sdk/signature-v4&quot;;<br>import { formatUrl } from &quot;@aws-sdk/util-format-url&quot;;<br>import { HttpRequest } from &quot;@smithy/protocol-http&quot;;<br><br><br>interface AWSCredentials {<br>  accessKeyId: string; //REQUIRED<br>  secretAccessKey: string; //REQUIRED<br>  sessionToken: string; //REQUIRED<br>  expiration?: Date;<br>}<br><br>const IOT_ENDPOINT = &quot;{END_POINT}-ats.iot.{SERVICE_REGION}.amazonaws.com&quot;;<br>const REGION = &quot;SERVICE_REGION&quot;;<br><br>// Assumes you have the credentials from a signed in user<br>async function getSignedIotUrl(credentials: AWSCredentials) {<br>  // Prepare the request<br>  const request = new HttpRequest({<br>    protocol: &quot;wss:&quot;, // Websocket protocol<br>    hostname: IOT_ENDPOINT,<br>    method: &quot;GET&quot;,<br>    path: &quot;/mqtt&quot;,<br>    headers: { host: IOT_ENDPOINT },<br>  });<br>  // SIGN THE REQUEST<br>  const signedRequest = await new SignatureV4({<br>    credentials: {<br>      accessKeyId: credentials.accessKeyId,<br>      secretAccessKey: credentials.secretAccessKey,<br>      //Adding Session token here will NOT work<br>    },<br>    REGION,<br>    service: &quot;iotdevicegateway&quot;,<br>    sha256: Sha256,<br>  }).presign(request);<br>  const signedUrl = new URL(formatUrl(signedRequest));<br>  <br> //CRITICAL: Append session token HERE<br> signedUrl.searchParams.append(&quot;X-Amz-Security-Token&quot;, credentials.sessionToken);<br>  <br><br>  return signedUrl.toString(),<br>}<br><br></pre><p>For completeness, you can use <em>mqttjs</em> or <em>Paho mqtt </em>client<em> </em>libraries<em> </em>to connect. In example below I used <em>mqttjs</em>:</p><pre>import mqtt, { type MqttClient } from &quot;mqtt&quot;;<br><br><br>const signedUrl = await getSignedIotUrl(...);<br>// generate a random client id<br>const iotClientId = crypto.randomUUID();<br>const client = mqtt.connect(<br>  signedUrl, <br>  { clientId: iotClientId, reconnectPeriod: 5_000}<br>);<br>client.on(&quot;connect&quot;, () =&gt; {<br>  console.log(&quot;Yay connection successful!&quot;)<br>});<br>client.on(&quot;error&quot;, () =&gt; {<br>  console.error(&quot;Ooops something went wrong&quot;)<br>});<br></pre><p>Below are the npm packages needed to run the code snippets</p><pre>@aws-crypto/sha256-browser<br>@aws-sdk/signature-v4<br>@aws-sdk/util-format-url<br>@smithy/protocol-http<br>mqtt</pre><blockquote>Random quote:<br>Your life matters more than you think</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2af8dc4f23b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>