Skip to content
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

AWSIotMqttManager constructor does not accept endpoint in cn-north-1 region #337

Closed
a1exwang opened this issue Sep 7, 2017 · 5 comments
Closed
Labels
iot Issues with the AWS Android SDK for Internet of Things (IoT) question General question

Comments

@a1exwang
Copy link

a1exwang commented Sep 7, 2017

To help us solve your problem better, please answer the following list of questions.

  • What service are you using?

    • AWS IoT
  • In what version of SDK are you facing the problem?

    compile 'com.amazonaws:aws-android-sdk-core:2.4.7
    compile 'com.amazonaws:aws-android-sdk-s3:2.4.7
    compile 'com.amazonaws:aws-android-sdk-iot:2.4.7
  • Is the issue limited to Simulators / Actual Devices?

    • No
  • Can your problem be resolved if you bump to a higher version of SDK?

    • No. I read the code in the latest version 3876d78, the problem still exists.
  • Is this problem related to specific Android/OS version?

    • No
  • Can you give us steps to reproduce with a minimal, complete, and verifiable example? Please include any specific network conditions that might be required to reproduce the problem.

        new AWSIotMqttManager(clientId, "xxxxxxxx.iot.cn-north-1.amazonaws.com.cn");
  • Please include a stacktrace if applicable.
09-07 13:55:23.320 3480-3480/a1ex.wang.awsiottest E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: a1ex.wang.awsiottest, PID: 3480
                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{a1ex.wang.awsiottest/a1ex.wang.awsiottest.MainActivity}: java.lang.IllegalArgumentException: Bad endpoint format.  Expected XXXXXX.iot.[region].amazonaws.com.
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2666)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727)
                                                                        at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:154)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6121)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
                                                                     Caused by: java.lang.IllegalArgumentException: Bad endpoint format.  Expected XXXXXX.iot.[region].amazonaws.com.
                                                                        at com.amazonaws.mobileconnectors.iot.AwsIotEndpointUtility.validateIotEndpoint(AwsIotEndpointUtility.java:58)
                                                                        at com.amazonaws.mobileconnectors.iot.AwsIotEndpointUtility.getAccountPrefixFromEndpont(AwsIotEndpointUtility.java:83)
                                                                        at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.<init>(AWSIotMqttManager.java:520)
                                                                        at a1ex.wang.awsiottest.MainActivity.onCreate(MainActivity.kt:59)
                                                                        at android.app.Activity.performCreate(Activity.java:6682)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2619)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2727) 
                                                                        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:154) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:6121) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 

If you need help with understanding how to implement something in particular then we suggest that you first look into our developer guide. You can also simplify your process of creating an application by using Mobile Hub.

@mutablealligator mutablealligator added iot Issues with the AWS Android SDK for Internet of Things (IoT) question General question labels Sep 12, 2017
@a1exwang
Copy link
Author

AWS China confirms it as a bug..

@mutablealligator
Copy link
Contributor

Sorry for the inconvenience caused. We released 2.6.6 that fixes this issue. Can you check it out?

@pwa16000
Copy link

pwa16000 commented Nov 6, 2017

Hi,

I tried 2.6.6 recently, the Exception does not exist anymore, but still can't connect to AWS IoT.

The sample program I run was https://github.com/awslabs/aws-sdk-android-samples/tree/master/AndroidPubSub. with similar configuration, I can connect to AWS IoT us-west-2 region, but for cn-north-1, it always failure.

####################################
git diff HEAD
diff --git a/AndroidPubSub/build.gradle b/AndroidPubSub/build.gradle
....................................
diff --git a/AndroidPubSub/src/com/amazonaws/demo/androidpubsub/PubSubActivity.java b/AndroidPubSub/src/com/amazonaws/demo/androidpubsub/PubSubActivity
index 04410f7..19bf059 100644
--- a/AndroidPubSub/src/com/amazonaws/demo/androidpubsub/PubSubActivity.java
+++ b/AndroidPubSub/src/com/amazonaws/demo/androidpubsub/PubSubActivity.java
@@ -49,15 +49,15 @@ public class PubSubActivity extends Activity {

 // IoT endpoint
 // AWS Iot CLI describe-endpoint call returns: XXXXXXXXXX.iot.<region>.amazonaws.com
  • private static final String CUSTOMER_SPECIFIC_ENDPOINT = "xxxxxnzc4rs7q.iot.us-west-2.amazonaws.com";
  • private static final String CUSTOMER_SPECIFIC_ENDPOINT = "xxxxxkbb9j48a.iot.cn-north-1.amazonaws.com.cn";
    // Cognito pool ID. For this app, pool needs to be unauthenticated pool with
    // AWS IoT permissions.
  • private static final String COGNITO_POOL_ID = "us-west-2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  • private static final String COGNITO_POOL_ID = "cn-north-1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    // Name of the AWS IoT policy to attach to a newly created certificate
  • private static final String AWS_IOT_POLICY_NAME = "MyRaspberryPiPolicy";
  • private static final String AWS_IOT_POLICY_NAME = "MyRaspberryPiNum01Policy";

    // Region of AWS IoT

  • private static final Regions MY_REGION = Regions.US_WEST_2;
  • private static final Regions MY_REGION = Regions.CN_NORTH_1;
    // Filename of KeyStore file on the filesystem
    private static final String KEYSTORE_NAME = "iot_keystore";
    // Password for the private key in the KeyStore
    ######################################

I tried use manual build keystore to access, I can't connect to AWS IoT cn-north-1 region also.
The way I do is: store private key and certificate to 2 strings, then create keystore, then use it to connect. but failed always.

 try {
        if (AWSIotKeystoreHelper.isKeystorePresent(keystorePath,keystoreName)){
            if(AWSIotKeystoreHelper.keystoreContainsAlias(certificateId,keystorePath,keystoreName,keystorePassword)){
                AWSIotKeystoreHelper.deleteKeystoreAlias(certificateId,keystorePath,keystoreName,keystorePassword);
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "An error occurred delete alias from keystore.", e);
    }
    AWSIotKeystoreHelper.saveCertificateAndPrivateKey(certificateId, certPem, keyPem,keystorePath,keystoreName,keystorePassword);

Could you please help have a check?

Best regard
Philip

@mutablealligator
Copy link
Contributor

Hi @pwa16000,

Can you try upgrading to 2.6.7 and check if it's fixed?

@a1exwang
Copy link
Author

a1exwang commented Dec 8, 2017

Yes, It is working. Thanks!

@a1exwang a1exwang closed this as completed Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iot Issues with the AWS Android SDK for Internet of Things (IoT) question General question
Projects
None yet
Development

No branches or pull requests

3 participants