AWS Cost Explorer – enables you to visualize your usage patterns over time and to identify your underlying cost drivers. AWS Pricing Calculator – create cost estimates to suit your AWS use cases. AWS Cost Explorer. The AWS Cost Explorer is a free tool that allows you to view charts of your costs. I also love Amazon Elastic Beanstalk (EB). When you create a new EB environment and have supplied an email address for receiving notifications, EB will set up a new Simple Notification.
Latest versionReleased:
AWS package which creates a Slack subscriber to a SNS Topic.
Project description
AWS SNS Slack Subscriber
A library that creates a slack subscriber to your aws sns topic.
Remarks
Aws Chatbot
The project is written by Laimonas Sutkus and is owned byiDenfy. This is an open sourcelibrary intended to be used by anyone. iDenfy aimsto share its knowledge and educate market for better and more secure IT infrastructure.
Related technology
This project utilizes the following technology:
- AWS (Amazon Web Services).
- AWS CDK (Amazon Web Services Cloud Development Kit).
- AWS Lambda.
- AWS Sns.
- Slack.
Install
The project is built and uploaded to PyPi. Install it by using pip.
Or directly install it through source.
Description
When you have SNS Topics, you may subscribe to them with various ways. For example,email subscription will send an email to a desired email address when a notificationis pushed to a SNS Topic. Most of the time email subscription is not ideal as it mayclutter your email box. Hence, there are other ways to subscribe to a SNS Topic. Wethink the most convenient way to subscribe to SNS Topic is a Lambda Function integrationwhich sends callbacks to your specified Slack channel. This library project is about that.It creates a 'Slack subscription' with a help of Lambda.
Examples
Create sns slack subscriber as any other lambda function:
2.2.0
Force update 1.60.0 and add upper bound of 2.0.0.
2.1.0
URL and AWS CDK updates.
1.1.1
Completely refactor functionality. Add an explicit pipeline handler.Rewrite everything on python.
1.1.1
Add js file to manifest.
1.1.0
Add ability to specify slack channel.
1.0.0
Initial commit.
Release historyRelease notifications | RSS feed
2.2.0
2.1.0
2.0.0
1.1.1
1.1.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size aws_sns_slack_subscriber-2.2.0-py3-none-any.whl (21.3 kB) | File type Wheel | Python version py3 | Upload date | Hashes |
Filename, size aws_sns_slack_subscriber-2.2.0.tar.gz (5.1 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for aws_sns_slack_subscriber-2.2.0-py3-none-any.whl
Algorithm | Hash digest |
---|---|
SHA256 | bfbd3f114f35fd02ee91dd0f86523a42904405642f2932d38559ac6d188c96d3 |
MD5 | 6a1693dbf8e715ef63da562eb5fe8297 |
BLAKE2-256 | 3d62a0c990e087d34df882c18ed70ef28e07e3f5402d10a6597a562db49490e8 |
Hashes for aws_sns_slack_subscriber-2.2.0.tar.gz
Algorithm | Hash digest |
---|---|
SHA256 | d4a06269d5fb00f49da9c92db882529ecce47caa765257070bb07a425077d011 |
MD5 | 58e65305a7acb90707ac20f3774b13c8 |
BLAKE2-256 | 77a48195da732880ac6f45e4665e7eef861868d78b7b3cc1739fe0530a0d808e |
By default, when managing a large number of EC2 instances, you don't get a lot of visibility into how your instances are behaving. Any monitoring beyond what you get in the console needs to be configured and set up by the AWS user using services like Cloudwatch or Cloudtrail, etc.
EC2 instances can be started or stopped for various reasons by anyone with access to the EC2 console, and your team might want to know about it.
In Zuar's case we manage hundreds of EC2 instances across three regions running our products Mitto, Rapid Portal and Custom Portal. We wanted to get notifications in our #devops slack channel anytime an instance state changed.
Aws Sns To Slack Transfer
If you're familiar with Terraform feel free to skip everything below! Simply Edit and use this code.
Overview
AWS Cloudwatch allows you to create rules which will publish to an SNS topic any time a specific EC2 instance or list of instances has a state change. You can subscribe emails to this SNS topic and receive emails anytime there's a new SNS publication. In this case, we'll subscribe a custom Lambda function, that formats the slack message, and then makes a POST request to our slack channel.
Flow
- A user on your AWS account stops an EC2 instance.
- Your Cloudwatch Event Rule is triggered and publishes to your SNS Topic
- SNS invokes your Lambda function with the message Cloudwatch published
- Your Lambda function formats the message for slack and does a POST request to your webhook.
Results
The messages in your slack channel should look something like this:
Slack Webhook
First and foremost, you need a Slack channel with an incoming webhook. It should give you a link similar to this which we will use later in our Lambda function: https://hooks.slack.com/services/UNIQUE_ID/UNIQUE_ID/UNIQUE_ID .. You can test that the link is working using curl like this:
Lambda Function
I won't get into the specifics of Lambda deployment here. It'll need an execution role, a policy, and a policy attachment, some of which the console will create for you. Later you will add a trigger for SNS. Our Lambda uses Python3.6 and there are 4 environment variables you will need to set. ACCESSKEY, SECRETKEY, REGION and SLACK_HOOK. Below is our lambda function:
NOTE: When packaging this for deployment, be sure to include requests
as a dependency.
Simple Notification Service (SNS)
Still with me? Next you'll need to create an SNS topic, and then create a subscription with your Lambda function. In the SNS console you would click 'Create Topic'. All you need here is a name. Once that's done, you'll go to 'Subscriptions' and create a subscription. enter the ARN for the topic you just created, select 'AWS Lambda' as the protocol, and then select the ARN for the Lambda we created.
Cloudwatch Rule
Aws Slack Group
In the Cloudwatch console. Click on 'Rules' under events in the menu on the left. Click on 'Create Rule'. On the left select 'Event Pattern', service 'EC2', event type 'EC2 Instance State-change Notification'. Select 'Any state' and 'Any Instance' to publish to SNS on changes to any instance in this region.
On the right select 'SNS Topic' at the top then select the SNS topic you created. Below that select 'input transformer'. In the first textarea use:
Aws Sns Webhook
and in the Second textarea use:
Our Lambda function will expect the format above.
Save your changes, and it's time to do some testing.
Testing and Troubleshooting
To test everything we just created, simply go to the EC2 console and start and stop an instance you're not using in the region you created your resources in. If you don't get a message in your slack channel, check the cloudwatch logs for your Lambda function and ensure that the function was invoked. If the function was not invoked, you might need an SNS trigger on your Lambda function. Also double check you have all the permissions, roles, and policies you need for Lambda to receive events and be invoked by SNS.