question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SDK Assistance (Angular 9)

See original GitHub issue

Confirm by changing [ ] to [x] below:

Known Issue

  • I’m using ATS data type endpoint: the endpoint should look like <prefix>-ats.iot.<region>.amazonaws.com

Platform/OS/Hardware/Device What are you running the sdk on? Ionic 5 (Angular 9), aws-iot-device-sdk-v2, MacOS Catalina

Node: 12.16.2 NPM: 6.14.7

Describe the question Hi,

I have read the basic PubSub docs & Examples here (multiple times), and been trying to understand the basic flow of it. Would you mind showing me the way towards how to properly establish the connection to AWS IoT via MQTT, and one example of Sub?

Here’s what I have, and stuck in confusion.

import { Injectable } from '@angular/core';
import { iot } from 'aws-iot-device-sdk-v2';

@Injectable({
  providedIn: 'root'
})
export class AWSIoTService {

  constructor() { }

  async connect() {
    let config = null;
    config = iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path('file.private.key', 'file.cert.pem')
      .with_certificate_authority_from_path('root-CA.crt')
      .with_port(8863)
      .with_endpoint('xxxx-ats.iot.ap-southeast-1.amazonaws.com')
      .build();
    console.log('Main');
  }
}
ERROR in node_modules/aws-crt/dist/native/auth.d.ts:5:8 - error TS1192: Module '"/Users/raeveen/Documents/client/node_modules/aws-crt/dist/native/binding"' has no default export.

5 import crt_native from './binding';
         ~~~~~~~~~~
node_modules/aws-crt/dist/native/http.d.ts:5:8 - error TS1192: Module '"/Users/raeveen/Documents/client/node_modules/aws-crt/dist/native/binding"' has no default export.

5 import crt_native from './binding';
ERROR in ./node_modules/aws-crt/dist.browser/browser/http.js
Module not found: Error: Can't resolve '@awscrt/io' in '/Users/raeveen/Documents/Ionic Development/quix/quix-admin-dashboard/node_modules/aws-crt/dist.browser/browser'

Appreciate your time and assistance for a small kick start.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
InspectorGadgetcommented, Aug 15, 2020

Hi @KaibaLopez,

I can now confirm that this issue is now resolved.

The latest release in aws-crt did the trick.

Thank you for your assistance.

1reaction
KaibaLopezcommented, Aug 12, 2020

Ok, new update. I’ve managed to get it to work there is a few things that I had to change besides the ones I mentioned on the comment above.

So, the issue is that some methods and classes are just not browser compatible, like ‘new_mtls_builder_from_path’ for example, the only way I found to establish a connection is through new_with_websockets, so that would change the code a bit:

ngOnInit() {
    const client_bootstrap = new io.ClientBootstrap();
    const myClient = iot.AwsIotMqttConnectionConfigBuilder
      .new_with_websockets({
        region: region,
        credentials_provider: undefined, //Credential provider is part of auth which isn't available for browser.
        proxy_options: undefined
    });
    let config = myClient.with_client_id(someId) // unique ClientId for each connection.
    .with_credentials(region, accessId, privateKey, '') //because we had no credentials provider set, we have to manually add them, I recommend using cognito.
    .with_endpoint('xxxxxx-ats.iot.region.amazonaws.com')
    .build();
    const client = new mqtt.MqttClient(client_bootstrap);
    const connection = client.new_connection(config);
    connection.connect();
  }

This way i got a connection established using the sample you provided, I know it is not yet a pub_sub yet but I hope it helps you get there and let me know if you need some other help with that. Also, I never encountered the error from the original post, was that also happening on your the sample code you provided? Does it keep happening after the changes I suggested?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular versioning and releases
Minor releases are fully backward-compatible; no developer assistance is expected during update, but you can optionally modify your applications and ...
Read more >
API List - Angular
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces ......
Read more >
Angular
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces ......
Read more >
angular/service-worker
Implements a service worker for Angular apps. Adding a service worker to an Angular app is one of the steps for turning it...
Read more >
CLI Overview and Command Reference - Angular
Online help is available on the command line. Enter the following to list commands or options for a given command (such as generate)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found