Skip to content

Using AWS IoT Core policy variables won't work (Cognito) #139

@tivaliy

Description

@tivaliy
  • I've searched for previous similar issues and didn't find any solution

Platform/OS/Device
macOS Catalina, python3.8

Describe the question
I faced with a weird behaviour using SDK and policy variables. The problem is that when I use AWS IoT Core policy variables then I'm not able to even connect to IoT Service.

Steps:

  1. Create a thing in AWS IoT Registry, e.g. dummy (without any certificates).
  2. Create a policy document:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": [
        "arn:aws:iot:us-east-1:XXXXXXXX:client/${iot:Connection.Thing.ThingName}"
      ]
    }
  ]
}
  1. Attach a principal to the policy.
  2. Configure IAM roles.
  3. ...

Then I'm trying to connect:

mqtt_connection = mqtt_connection_builder.websockets_with_default_aws_signing(
    endpoint=host,
    client_bootstrap=client_bootstrap,
    region='us-east-1',
    credentials_provider=credentials_provider,
    websocket_proxy_options=None,
    ca_filepath=path_to_file,
    on_connection_interrupted=on_connection_interrupted,
    on_connection_resumed=on_connection_resumed,
    client_id='dummy',
    clean_session=False,
    keep_alive_secs=6)

connect_future = mqtt_connection.connect()
connect_future.result()

with the following result:

AwsCrtError: AwsCrtError(name='AWS_ERROR_MQTT_UNEXPECTED_HANGUP', message='The connection was closed unexpectedly.', code=5134)

However, when I change the policy document to a "hardcoded" thing name value (dummy) it works:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "iot:Connect",
      "Resource": [
        "arn:aws:iot:us-east-1:XXXXXXXX:client/dummy"
      ]
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    automation-exemptThis issue will not be closed by autoclose actionfeature-requestA feature should be added or improved.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions