awslabs / aws-crt-python

Python bindings for the AWS Common Runtime
Apache License 2.0
87 stars 43 forks source link

"RuntimeError: 0 (AWS_ERROR_SUCCESS): Success." occured when executing mqtt_connection_builder.mtls_from_path() on Amazon EC2 Mac instance #234

Closed mayosuke closed 1 year ago

mayosuke commented 3 years ago

"RuntimeError: 0 (AWS_ERROR_SUCCESS): Success." occurred when executing mqtt_connection_builder.mtls_from_path() when I tried to create MQTT connection to AWS IoT from Amazon EC2 Mac instance. I was expecting to complete the execution successfully. I've succeeded to create MQTT connection with the same test code and the certificates on other environments like Linux.

It seems that something unexpected happened in C library, but it's difficult for me to investigate. I've really appreciated it if someone helps me.

Testing configuration

Testing code and result

test_mqtt.py

# -*- coding: utf-8 -*-
from awscrt import io
from awsiot import mqtt_connection_builder

deviceId = "TEST1234"
endPoint = "XXXX-ats.iot.ap-northeast-1.amazonaws.com"
rootCA = "./root-CA.crt"
certificate = "./certificate.pem.crt"
privateKey = "./private.pem.key"

event_loop_group = io.EventLoopGroup(1)
host_resolver = io.DefaultHostResolver(event_loop_group)
client_bootstrap = io.ClientBootstrap(event_loop_group, host_resolver)

mqtt_connection = mqtt_connection_builder.mtls_from_path(
    endpoint=endPoint,
    cert_filepath=certificate,
    pri_key_filepath=privateKey,
    client_bootstrap=client_bootstrap,
    ca_filepath=rootCA,
    client_id=deviceId,
    clean_session=False,
    keep_alive_secs=6)
print(f"Connecting to {endPoint} with client ID '{deviceId}'...")

connected_future = mqtt_connection.connect()
connected_future.result()
print("Connected!")
% python3 test_mqtt.py                   
Traceback (most recent call last):
  File "test_mqtt.py", line 16, in <module>
    mqtt_connection = mqtt_connection_builder.mtls_from_path(
  File "/Users/ec2-user/tmp/.venv-3.8.7-2/lib/python3.8/site-packages/awscrt/awsiot_mqtt_connection_builder.py", line 201, in mtls_from_path
    return _builder(tls_ctx_options, **kwargs)
  File "/Users/ec2-user/tmp/.venv-3.8.7-2/lib/python3.8/site-packages/awscrt/awsiot_mqtt_connection_builder.py", line 162, in _builder
    tls_ctx = awscrt.io.ClientTlsContext(tls_ctx_options)
  File "/Users/ec2-user/tmp/.venv-3.8.7-2/lib/python3.8/site-packages/awscrt/io.py", line 409, in __init__
    self._binding = _awscrt.client_tls_ctx_new(
RuntimeError: 0 (AWS_ERROR_SUCCESS): Success.
bretambrose commented 3 years ago

If you can, please attach CRT trace level logs, per https://github.com/awslabs/aws-crt-python/blob/main/awscrt/io.py#L27