无法从 Raspberry Pi 访问 AWS IoT Greengrass 中的 root.ca.pem 文件

Unable to access root.ca.pem file in AWS IoT Greengrass from Raspberry Pi

我正在尝试从 Raspberry Pi 4.

的 IoT Core 发布消息
import time
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient

def hello(self,params,packet):
    print("Received Message from AWS IoT Core")
    print(f"Topic: {packet.topic}")
    print(f"Payload: {packet.payload}")

myMQTTClient = AWSIoTMQTTClient("YudhieshID")
// Did not include endpoint here for security reasons
myMQTTClient.configureEndpoint("",8883)

myMQTTClient.configureCredentials("/home/pi/greengrass/certs/root.ca.pem", "/home/pi/greengrass/certs/22e7469561.private.key","/home/pi/greengrass/certs/22e7469561.cert.pem")
myMQTTClient.configureOfflinePublishQueueing(-1)
myMQTTClient.configureDrainingFrequency(2)
myMQTTClient.configureConnectDisconnetTimeout(10)
myMQTTClient.configureMQTTOperationTimeout(5)
print("INtitating IoT Core Topic...")
myMQTTClient.connect()
myMQTTClient.subscribe("home/helloworld",1,hello)

while True:
    time.sleep(5)

错误:

OSError: /home/pi/greengrass/certs/root.ca.pem: No such file or directory

/greengrass/certs 表明文件在那里:

pi@raspberrypi:/greengrass/certs $ tree ./
./
|-- 22e7469561.cert.pem
|-- 22e7469561.private.key
|-- 22e7469561.public.key
|-- README
`-- root.ca.pem

我已经运行使用以下命令将根 CA 证书下载到 /greengrass/certs 文件夹:

cd /greengrass/certs/
sudo wget -O root.ca.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem

我还确认 root.ca.pem 文件不为空,使用:

cat root.ca.pem

通过将文件路径更改为:

设法修复了它
myMQTTClient.configureCredentials("/greengrass/certs/root-ca.pem", "/greengrass/certs/22e7469561.private.key","/greengrass/certs/22e7469561.cert.pem")

但在这样做时我必须 运行 sudo 运行 python 脚本才能访问证书。