What minimal IAM permissions are needed by AWS Chatbot so that it can show logs? The AWS service called Chatbot allows CloudWatch Alarms to be relayed into a Slack channel. The message includes two buttons: Show logs and Show error logs.

However, when I press either of these buttons, I receive an error message like this:

❗️ I can't get the logs for you because the role arn:aws:iam::123412341234:role/my-chatbot in account 123412341234 is missing necessary permissions related to commands.
If you want to get logs, go to the AWS Chatbot console and choose or create a role that includes Read-only command permission for this channel.

However, the recommended way of accomplishing this (the way automatically set up by AWS Console) grants Chatbot the ReadOnlyAccess policy which is way too permissive for my tastes. I don't want Chatbot to be able to read any object from any of our S3 buckets!
What is the minimal IAM policy that enables Chatbot to read CloudWatch Logs for Lambda functions?
AWS Chatbot uses CloudWatch Logs Insights, so the IAM policy for Chatbot must include these two statements:
{
    &quot;Sid&quot;: &quot;QueryLogs&quot;,
    &quot;Effect&quot;: &quot;Allow&quot;,
    &quot;Action&quot;: [
        &quot;logs:StopQuery&quot;,
        &quot;logs:StartQuery&quot;,
        &quot;logs:DescribeQueries&quot;
    ],
    &quot;Resource&quot;: &quot;arn:aws:logs:::log-group:/aws/lambda/*&quot;
},
{
    &quot;Sid&quot;: &quot;GetQueryResults&quot;,
    &quot;Effect&quot;: &quot;Allow&quot;,
    &quot;Action&quot;: &quot;logs:GetQueryResults&quot;,
    &quot;Resource&quot;: &quot;*&quot;
}

With these statements in place, pressing the logs button will yield an initial message from Chatbot like this:

I ran this CloudWatch Logs Insights query to fetch logs from 2020-11-18T09:02 UTC to 2020-11-18T09:07 UTC.

... as well as several follow-up messages containing a plaintext dump of the logs.