'Publish to topic from AWS Lambda stop working

I have a Lambda function that has been working without issue for several months. Starting a couple of days ago, now a publish to an MQTT client always times out. Here's the publish code:

    client = boto3.client('iot-data', region_name='us-east-1')
    client.publish(topic= 'sdk/test/Python',qos=1,payload=mypayload)

From the log file:

2020-12-18T13:57:35.652Z 6660d942-766d-419e-88d2-c09c11dd33cc Task timed out after 3.00 seconds

The client is running on a raspberrypi. I can publish to the topic from the Iot test console and the client running on the rpi that subscribed to the topic receives the test messages.

If I subscribe to the topic using the Iot test console, messages are NOT received

There's an inline policy for the lambda function for the publish:

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

How do I fix or debug this? The 3 second timeout should be plenty long enough, so I haven't tried making it long.



Solution 1:[1]

I too had this issue and was able to resolve it by changing the Lambda runtime to use the latest Python version (3.8).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dave Crumbacher