AWSIotClient createKeysAndCertificate stopped working in production Application

Viewed 181

createKeysAndCertificate stopped working in the production application, it was working perfectly but suddenly started giving UnknownOperationException with status code 400. Please help me for the same. Here is the code which is used to create keys and certificate. TIA

   Thread(Runnable {

            try {
             

                val createKeysAndCertificateRequest = CreateKeysAndCertificateRequest()
            


                createKeysAndCertificateRequest.setAsActive = true
         

                val createKeysAndCertificateResult: CreateKeysAndCertificateResult

                createKeysAndCertificateResult=mIotAndroidClient.createKeysAndCertificate(createKeysAndCertificateRequest)

          


                // store in keystore for use in MQTT client
                // saved as alias "default" so a new certificate isn't
                // generated each run of this application
                AWSIotKeystoreHelper.saveCertificateAndPrivateKey(certificateId,
                        createKeysAndCertificateResult.certificatePem,
                        createKeysAndCertificateResult.keyPair.privateKey,
                        keystorePath, keystoreName, keystorePassword)


                // loadad keystore from file into memory to pass on
                // connection
                clientKeyStore = AWSIotKeystoreHelper.getIotKeystore(certificateId,
                        keystorePath, keystoreName, keystorePassword)
            


                // Attach a policy to the newly created certificate.
                // This flow assumes the policy was already created in
                // AWS IoT and we are now just attaching it to the
                // certificate.
                val policyAttachRequest = AttachPrincipalPolicyRequest()
              

                policyAttachRequest.policyName = AwsManager.AWS_IOT_POLICY_NAME
                policyAttachRequest.principal = createKeysAndCertificateResult
                        .certificateArn
                mIotAndroidClient.attachPrincipalPolicy(policyAttachRequest)
                Log.i(TAG, "onCreate: attachPrincipalPolicy")

                runOnUiThread {
                    // if(!this.isFinishing && progressDialog.isShowing)
                    //   progressDialog.dismiss()
                }
            }catch ( e:java.lang.Exception){
               Log.e(TAG,
                     "Exception occurred when generating new private key and certificate."+
                       e.message);
            }
        }).start()

Here is the exact log

com.amazonaws.AmazonServiceException:  (Service: AWSIot; Status Code: 400; Error Code: UnknownOperationException; Request ID: 8bc52f99-850a-4d3d-9a50-ad03833)
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:731)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:405)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:212)
    at com.amazonaws.services.iot.AWSIotClient.invoke(AWSIotClient.java:11411)
    at com.amazonaws.services.iot.AWSIotClient.createKeysAndCertificate(AWSIotClient.java:1697)
    at com.proj.login.LoginActivity$generateKey$1.run(LoginActivity.kt:496)
    at java.lang.Thread.run(Thread.java:919)
0 Answers
Related