feat(aws): send notifications to slack channels

This commit is contained in:
Michele Cereda
2025-02-03 23:20:08 +01:00
parent b0b3caebd0
commit 8b626edc28
9 changed files with 530 additions and 2 deletions

View File

@@ -105,6 +105,8 @@ One can can rapidly remapping addresses to other instances in one's account and
| [S3] | Storage |
| [Sagemaker] | Machine learning |
| [Security Hub] | Aggregator for security findings |
| [SNS] | Pub/sub message delivery |
| [SQS] | Queues |
[Service icons][aws icons] are publicly available for diagrams and such.
Public service IP address ranges are [available in JSON form][aws public ip address ranges now available in json form]
@@ -510,6 +512,8 @@ machine if not.
[route53]: route53.md
[s3]: s3.md
[sagemaker]: sagemaker.md
[sns]: sns.md
[sqs]: sqs.md
<!-- Upstream -->
[access aws services through aws privatelink]: https://docs.aws.amazon.com/vpc/latest/privatelink/privatelink-access-aws-services.html

View File

@@ -0,0 +1,81 @@
# Chatbot
Enables using messaging program chat rooms to monitor, and respond to, operational events in AWS by processing service
notifications from SNS and forwarding them to chat rooms like Slack channels.
One can also run AWS CLI commands in chat channels using Chatbot.
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
Chatbot has **no** additional charge, minimum fees nor upfront commitments.<br/>
One will pay for the underlying services (SNS, SQS, CloudWatch, …).
Supports Amazon Chime, Microsoft Teams, and [Slack] at the time of writing.
<!-- Uncomment if used
<details>
<summary>Setup</summary>
```sh
```
</details>
-->
<details>
<summary>Usage</summary>
```sh
# List Slack workspaces.
aws chatbot describe-slack-workspaces
aws chatbot describe-slack-workspaces --query 'SlackWorkspaces'
# Show Slack channel configurations.
aws chatbot describe-slack-channel-configurations
aws chatbot describe-slack-channel-configurations --query 'SlackChannelConfigurations'
```
</details>
<!-- Uncomment if used
<details>
<summary>Real world use cases</summary>
```sh
```
</details>
-->
## Further readings
- [Website]
- [Documentation]
- [Slack]
- [SNS]
### Sources
- [What is AWS Chatbot?]
<!--
Reference
═╬═Time══
-->
<!-- In-article sections -->
<!-- Knowledge base -->
[slack]: ../../slack.md
[sns]: sns.md
<!-- Files -->
<!-- Upstream -->
[documentation]: https://docs.aws.amazon.com/chatbot/
[website]: https://aws.amazon.com/chatbot/
[what is aws chatbot?]: https://docs.aws.amazon.com/chatbot/latest/adminguide/what-is.html
<!-- Others -->

View File

@@ -0,0 +1,187 @@
# Simple Notification Service
Managed pub/sub message delivery service.
1. [TL;DR](#tldr)
1. [Connect a Slack channel to SNS](#connect-a-slack-channel-to-sns)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
_Publishers_ (or _producers_) send messages to a _topic_.<br/>
Topics are logical access points acting as communication channels for multiple _endpoints_ like SQS, emails, lambda,
and others.
SNS can be also used to send notifications to HTTP(S) endpoints such as Webhook URLs.<br/>
Anyway, SNS does **not** support sending requests using JSON key-value pairs, which some webhooks require (i.e. Slack).
_Subscribers_ (or _consumers_) subscribe to the topic and receive published messages using a supported endpoint type.
<details>
<summary><i>Standard</i> topics</summary>
- Do **not** enforce strict message ordering, grouping, **nor** deduplication.<br/>
Consumers of the queue may receive messages out of order, and more than once.
- Support **all** delivery protocols.
</details>
<details style="padding-bottom: 1em">
<summary><i>FIFO</i> topics</summary>
- Integrate with FIFO queues in [SQS].
- **Do** enforce strict message ordering, grouping, and deduplication.<br/>
They always deliver messages to subscribed [SQS] queues in the **exact** order in which the messages are published to
the topic, and **only once**.
- **Do** ensure strict message ordering, message grouping, and deduplication.
- Allowing FIFO and standard queues to subscribe for message processing.
</details>
By default, only the topic's owner can publish or subscribe to the topic.<br/>
Configure additional access permissions by expanding the topic's Access policy.
<!-- Uncomment if used
<details>
<summary>Setup</summary>
```sh
```
</details>
-->
<details>
<summary>Usage</summary>
```sh
# List topics.
aws sns list-topics
# Get information about topics.
aws sns get-topic-attributes --topic-arn 'arn:aws:sns:eu-west-1:012345678901:aSucculentTopic'
# List subscriptions.
aws sns list-subscriptions
aws sns list-subscriptions --query 'Subscriptions'
aws sns list-subscriptions-by-topic --topic-arn 'arn:aws:sns:eu-west-1:012345678901:aSucculentTopic'
# Get information about subscriptions.
aws sns get-subscription-attributes \
--subscription-arn 'arn:aws:sns:eu-west-1:012345678901:aSucculentTopic:abcdef01-2345-6789-abcd-ef0123456789'
```
</details>
<!-- Uncomment if used
<details>
<summary>Real world use cases</summary>
```sh
```
</details>
-->
## Connect a Slack channel to SNS
Refer [How to Connect AWS SNS to Slack using Webhooks: Easy Step-by-Step Explanation].
SNS does **not** currently support integrating directly with third-party applications.<br/>
Leverage [Slack's incoming webhooks] or create a [Chatbot] configuration for the destination Slack channel.
<details>
<summary>Webhook</summary>
SNS does **not** currently support sending requests using JSON key-value pairs, and Slack's webhooks require JSON
requests to include a message string as the value of the `text` key.<br/>
To solve this, use a Lambda function to modify the SNS message's body JSON document for the webhook endpoint.
Procedure:
1. Ensure the existence of a [Slack incoming webhook][slack's incoming webhooks] to send requests to.
1. Create a topic.<br/>
The _standard_ type is usually enough.
1. Create a Lambda function.<br/>
And test it works.
1. Add a topic trigger to the function.
<details>
<details>
<summary>Chatbot</summary>
1. Ensure the existence of a [Slack incoming webhook][slack's incoming webhooks] to send requests to.
1. Create a topic.<br/>
The _standard_ type is usually enough.
1. Create a IAM Role for the Chatbot configuration to use.
<details>
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "chatbot.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
```
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Autogenerated-AWS-Chatbot-NotificationsOnly-Policy",
"Effect": "Allow",
"Action": [
"cloudwatch:Describe*",
"cloudwatch:Get*",
"cloudwatch:List*"
],
"Resource": "*"
}
]
}
```
</details>
1. Create a Chatbot configuration for the destination Slack channel.
<details>
## Further readings
- [SQS]
### Sources
- [What is Amazon SNS?]
- [How To Set Up A Slack Channel To Be An AWS SNS Subscriber]
- [How to Connect AWS SNS to Slack using Webhooks: Easy Step-by-Step Explanation]
<!--
Reference
═╬═Time══
-->
<!-- In-article sections -->
<!-- Knowledge base -->
[chatbot]: chatbot.md
[sqs]: sqs.md
[slack's incoming webhooks]: ../../slack.md#incoming-webhooks
<!-- Files -->
<!-- Upstream -->
[what is amazon sns?]: https://docs.aws.amazon.com/sns/latest/dg/welcome.html
<!-- Others -->
[how to set up a slack channel to be an aws sns subscriber]: https://medium.com/cohealo-engineering/how-set-up-a-slack-channel-to-be-an-aws-sns-subscriber-63b4d57ad3ea
[how to connect aws sns to slack using webhooks: easy step-by-step explanation]: https://hevodata.com/learn/sns-to-slack/

View File

@@ -0,0 +1,62 @@
# Simple Queue Service
Managed queues.
1. [TL;DR](#tldr)
1. [Further readings](#further-readings)
1. [Sources](#sources)
## TL;DR
<!-- Uncomment if used
<details>
<summary>Setup</summary>
```sh
```
</details>
-->
<!-- Uncomment if used
<details>
<summary>Usage</summary>
```sh
```
</details>
-->
<!-- Uncomment if used
<details>
<summary>Real world use cases</summary>
```sh
```
</details>
-->
## Further readings
- [SNS]
### Sources
- [What is Amazon Simple Queue Service?]
<!--
Reference
═╬═Time══
-->
<!-- In-article sections -->
<!-- Knowledge base -->
[sns]: sns.md
<!-- Files -->
<!-- Upstream -->
[what is amazon simple queue service?]: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html
<!-- Others -->