This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto3 # AWS SDK for Python | |
| import os | |
| from base64 import b64decode | |
| # Retrieve environment variables | |
| encrypted_environment_variable_a = os.environ['a'] | |
| encrypted_environment_variable_b = os.environ['b'] | |
| # KMS Client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Verify the Slack Signature and Verification token | |
| def verify(raw_body, token, headers): | |
| try: | |
| # Define variables | |
| version_no = "v0" | |
| # Verify Signing Secret | |
| slack_signature = headers['X-Slack-Signature'] | |
| slack_request_timestamp = headers['X-Slack-Request-Timestamp'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "body": "payload=%7B%22type%22%3A%22interactive_message%22%2C%22actions%22%3A%5B%7B%22name%22...", | |
| "headers": { | |
| "Accept": "application/json,*/*", | |
| ... | |
| "Content-Type": "application/x-www-form-urlencoded", | |
| "X-Slack-Request-Timestamp": "1537...", | |
| "X-Slack-Signature": "v0=..." | |
| ... | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Post to Slack | |
| def post_to_slack(message, instance_info): | |
| # Slack users | |
| # cyoung = @cyoung | |
| # user_2 = @user_2 | |
| owner_dict = { | |
| "cyoung" : "xxxxxxxxx", | |
| "user_2" : "zzzzzzzzz" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # RDS instance fact finder | |
| def rds_fact_and_candidate_finder(session, rds_agelimit, rds_running_agelimit, reserved_til, nowdatetime): | |
| resource_type = 'RDS' | |
| client = session.client('rds') | |
| db_instances = client.describe_db_instances() | |
| for inst in db_instances['DBInstances']: | |
| start_time = None | |
| # Get instance owner & static value from tags |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # EC2 instance candidate finder | |
| def ec2_candidate_finder(response, agelimit, reserved_til, nowdatetime): | |
| resource_type = 'EC2' | |
| for instance in (response['Reservations']): | |
| InstanceId = (instance['Instances'][0]['InstanceId']) | |
| launch_time = (instance['Instances'][0]['LaunchTime']) | |
| tags = (instance['Instances'][0]['Tags']) | |
| inst_owner = None |
NewerOlder