aws / aws-iot-device-sdk-cpp

SDK for connecting to AWS IoT from a device using C++
http://aws-iot-device-sdk-cpp-docs.s3-website-us-east-1.amazonaws.com
Apache License 2.0
123 stars 111 forks source link

SubscribeCallback() is not being called in pub-sub-sample program #183

Closed trahman-khan closed 4 years ago

trahman-khan commented 4 years ago

Hi All, I have compiled the SDK on my Ubuntu VM and tried to run the pub-sub-sample program. I was expecting to see both the published and subscribed messages on the hardcoded topic but looks like it can publish the messages but nothing happens on the subscription. Below is the output:

[INFO] Wed Mar  4 18:58:55 2020
:680 [OpenSSL Wrapper] [140023712573248] [ConnectTCPSocket:L234] : resolved avkkmno6cibmr-ats.iot.us-west-2.amazonaws.com to 52.88.213.16
[INFO] Wed Mar  4 18:58:56 2020
:58 [Network Read] [140023677699840] [HandleConnack:L228] : Network Connect Response. Success : SDK Code 0.

******************************Entering Publish with no queuing delay unless queue is full!!**************************
Publish Payload : Hello from SDK : 1
Publish Packet Id : 3
Publish Payload : Hello from SDK : 2
Publish Packet Id : 4
Publish Payload : Hello from SDK : 3
Publish Packet Id : 5
Publish Payload : Hello from SDK : 4
Publish Packet Id : 6
Publish Payload : Hello from SDK : 5
Publish Packet Id : 7
Success : SDK Code 0.
Waiting!!! 1
Waiting!!! 2
Waiting!!! 3
Waiting!!! 4
Waiting!!! 5
Waiting!!! 6
Waiting!!! 7
Waiting!!! 8
Waiting!!! 9
Waiting!!! 10
Waiting!!! 11
Waiting!!! 12
Waiting!!! 13
Waiting!!! 14
Waiting!!! 15
Waiting!!! 16
Waiting!!! 17
Waiting!!! 18
Waiting!!! 19
Waiting!!! 20
Waiting!!! 21
Waiting!!! 22
Waiting!!! 23
Waiting!!! 24
Waiting!!! 25
Waiting!!! 26
Waiting!!! 27
Waiting!!! 28
Waiting!!! 29
Waiting!!! 30
Waiting!!! 31
Waiting!!! 32
Waiting!!! 33
Waiting!!! 34
Waiting!!! 35
Waiting!!! 36
Waiting!!! 37
Waiting!!! 38
Waiting!!! 39
Waiting!!! 40
Waiting!!! 41
Waiting!!! 42
Waiting!!! 43
Waiting!!! 44
Waiting!!! 45
Waiting!!! 46
Waiting!!! 47
Waiting!!! 48
Waiting!!! 49
Waiting!!! 50
Waiting!!! 51
Waiting!!! 52
Waiting!!! 53
Waiting!!! 54
Waiting!!! 55
Waiting!!! 56
Waiting!!! 57
Waiting!!! 58
Waiting!!! 59
Waiting!!! 60
Waiting!!! 61
Waiting!!! 62
Waiting!!! 63
Waiting!!! 64
Waiting!!! 65
Waiting!!! 66
Waiting!!! 67
Waiting!!! 68
Waiting!!! 69
Waiting!!! 70
Waiting!!! 71
Waiting!!! 72
Waiting!!! 73
Waiting!!! 74
Waiting!!! 75
Waiting!!! 76
Waiting!!! 77
Waiting!!! 78
Waiting!!! 79
Waiting!!! 80
Waiting!!! 81
Waiting!!! 82
Waiting!!! 83
Waiting!!! 84
Waiting!!! 85
Waiting!!! 86
Waiting!!! 87
Waiting!!! 88
Waiting!!! 89
Waiting!!! 90
Waiting!!! 91
Waiting!!! 92
Waiting!!! 93
Waiting!!! 94
Waiting!!! 95
Waiting!!! 96
Waiting!!! 97
Waiting!!! 98
Waiting!!! 99
Waiting!!! 100

*************************Results**************************
Pending published messages : 5
Total published messages : 5
Exiting Sample!!!!
Exiting Thread MQTT Keep alive Action!!
Successfully Exited Thread MQTT Keep alive Action!!
Exiting Thread TLS Read Action Runner!!
Successfully Exited Thread TLS Read Action Runner!!
Exiting Thread Outbound Action Processing!!
Successfully Exited Thread Outbound Action Processing!!

Any help would be great! Please let me know if any additional information is required.

trahman-khan commented 4 years ago

Resolved the issue. I had to update the policy for iot:* and after that, I was able to see the subscription messages. But, this is strange because I had iot:Subscribe present on the policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Subscribe",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "iot:Publish",
      "Resource": "*"
    }
  ]
}

Closing the issue but if anyone can please shed light on this policy puzzle :)