title: How to create presigned request with temporary credentiail
body: <p>With regard to <a href="https://docs.aws.amazon.com/iot/latest/developerguide/connect-iot-lorawan-network-analyzer-generate-request.html" rel="nofollow noreferrer">this</a> guide, I just need to add <code>X-Amz-Security-Token=[token]</code> to query params.</p>
  <p>My code works before I changed it to temporary credential.
  But with temporary credential,paho can't connect -</p>
  <pre><code>paho-mqtt.js:1054 WebSocket connection to 'wss://...' failed:
  </code></pre>
  <p>Server-side code -</p>
  <pre class="lang-js prettyprint-override"><code>export async function getEndpoint() {
    const serverCredential = await getServerCredential();
    const clientCredential = await getClientCredential();
  
    const host = serverCredential.endpoint;
    const time = moment.utc();
    const dateStamp = time.format('YYYYMMDD');
    const amzdate = dateStamp + 'T' + time.format('HHmmss') + 'Z';
    const service = 'iotdevicegateway';
    const region = serverCredential.region;
    const secretKey = clientCredential.SecretAccessKey;
    const accessKey = clientCredential.AccessKeyId;
    const algorithm = 'AWS4-HMAC-SHA256';
    const method = 'GET';
    const canonicalUri = '/mqtt';
  
    const credentialScope = dateStamp + '/' + region + '/' + service + '/' + 'aws4_request';
    let canonicalQuerystring = 'X-Amz-Algorithm=AWS4-HMAC-SHA256';
    canonicalQuerystring += '&amp;X-Amz-Credential=' + encodeURIComponent(accessKey + '/' + credentialScope);
    canonicalQuerystring += '&amp;X-Amz-Date=' + amzdate;
    canonicalQuerystring += '&amp;X-Amz-Expires=300';
    canonicalQuerystring += '&amp;X-Amz-SignedHeaders=host';
    canonicalQuerystring += '&amp;X-Amz-Security-Token=' + clientCredential.SessionToken;
  
    const canonicalHeaders = 'host:' + host + '\n';
    const payloadHash = SigV4Utils.sha256('');
    const canonicalRequest = method + '\n' + canonicalUri + '\n' + canonicalQuerystring + '\n' + canonicalHeaders + '\nhost\n' + payloadHash;
    console.log('canonicalRequest ' + canonicalRequest);
  
    const stringToSign = algorithm + '\n' + amzdate + '\n' + credentialScope + '\n' + SigV4Utils.sha256(canonicalRequest);
    const signingKey = SigV4Utils.getSignatureKey(secretKey, dateStamp, region, service);
    console.log('signingKey ' + signingKey);
    const signature = SigV4Utils.sign(signingKey, stringToSign);
  
    canonicalQuerystring += '&amp;X-Amz-Signature=' + signature;
    const requestUrl = 'wss://' + host + canonicalUri + '?' + canonicalQuerystring;
    return requestUrl;
  }
  </code></pre>
  <p>client-side code -</p>
  <pre class="lang-js prettyprint-override"><code>  async initMqttConnection() {
      console.log('initMqttConnection');
      const endPoint: any = await this.api.getMQTTEndPoint();
      const user = await this.user.getLoggedInUser().toPromise();
      MqttService.userId = user.email;
      MqttService.client = new Paho.Client(endPoint.endPoint, MqttService.userId);
      return new Promise&lt;void&gt;(resolve =&gt; {
        MqttService.client.connect({
          useSSL: true,
          timeout: 3,
          mqttVersion: 4,
          onSuccess: e =&gt; {
            MqttService.client.subscribe(this.commandTopic + '/commands_response/')
            console.log('Connected!', e);
            resolve();
        }});
        MqttService.client.onMessageArrived = message =&gt; {
          MqttService.onMessage.next(JSON.parse(message.payloadString));
        };
        MqttService.client.onConnectionLost = function (e) {
          console.log(e);
        };
      });
    }
  }
  </code></pre>
  <p>Any idea what I did wrong?</p>