Skip to content

Instantly share code, notes, and snippets.

@vvalorous
vvalorous / notify_slack.py
Created October 2, 2018 03:50 — forked from StevenACoffman/notify_slack.py
AWS Lambda function to send notifications from CodeDeploy to Slack
from __future__ import print_function
import json, urllib, urllib2
def send_slack(message):
"""
Send Slack Message to Deployments Channel
"""
slack_token = ''
slack_channel = ''
slack_user = 'Deployment Bot'
@vvalorous
vvalorous / lambda_handler_cloudformation.py
Created October 2, 2018 03:49 — forked from unacceptable/lambda_handler_cloudformation.py
This is a lambda handler that I am saving for the next time that I choose to execute lambda from a CloudFormation script.
def lambda_handler(event, context):
try:
logger.info(json.dumps(event,indent=4))
main(event, context)
responseStatus = 'SUCCESS'
responseData = {}
except Exception as msg:
logger.error(msg)
@vvalorous
vvalorous / SNSPostToSlack.py
Created October 2, 2018 03:48 — forked from unacceptable/SNSPostToSlack.py
This is a simple python script to post to Slack from a SNS Topic (CloudWatch Trigger).
#!/usr/bin/env python
# Written by: Robert J.
# Email: [email protected]
import boto3
import json
import logging
import os, sys
from urllib2 import Request, urlopen, URLError, HTTPError
@vvalorous
vvalorous / lambda_function.py
Created October 2, 2018 03:47 — forked from thara/lambda_function.py
AWS lambda blueprint : slack-echo-command-python written by Python 3
'''
This function handles a Slack slash command and echoes the details back to the user.
Follow these steps to configure the slash command in Slack:
1. Navigate to https://<your-team-domain>.slack.com/services/new
2. Search for and select "Slash Commands".
3. Enter a name for your command and click "Add Slash Command Integration".
@vvalorous
vvalorous / gist:d613d93089bc6f6883e0db6fc7e6b8e8
Created September 30, 2018 07:59 — forked from bigsnarfdude/gist:cb9bc2f3f99639f9bef7
cloudtrail event analysis local hdd python3 async await
#! /usr/local/env python
# coding: utf-8
import gzip
import json
from pprint import pprint
import pandas as pd
from pandas.io.json import json_normalize
import sys
@vvalorous
vvalorous / gist:0a2f270a0cb817c345de0c37b8fde7fc
Created September 30, 2018 07:58 — forked from bigsnarfdude/gist:a833143c198982710d85
cloudtrail console login on slack
#! /usr/local/env python
# coding: utf-8
import gzip
import json
from pprint import pprint
import pandas as pd
from pandas.io.json import json_normalize
import sys
import socket
@vvalorous
vvalorous / README.md
Created September 30, 2018 07:57 — forked from magnetikonline/README.md
Python AWS CloudTrail parser class.

Python AWS CloudTrail parser

A Python parser class for CloudTrail event archives, previously dumped to an S3 bucket. Class provides an iterator which will:

  • Scan a given directory for archive files matching the required pattern.
  • Decompress each archive in memory.
  • Parse JSON payload and return each event in turn.

Parser contained in cloudtrailparser.py, with timezone.py used as a simple datetime.tzinfo concrete class implement to provide UTC timezone.

Example

@vvalorous
vvalorous / privileges.txt
Created September 29, 2018 07:28 — forked from 0xdabbad00/privileges.txt
AWS IAM privileges as found using the AWS Policy Generator described at https://summitroute.com/blog/2018/06/28/aws_iam_vs_api_vs_cloudtrail/
a4b:AssociateDeviceWithRoom
a4b:AssociateSkillGroupWithRoom
a4b:CreateProfile
a4b:CreateRoom
a4b:CreateSkillGroup
a4b:CreateUser
a4b:DeleteProfile
a4b:DeleteRoom
a4b:DeleteRoomSkillParameter
a4b:DeleteSkillGroup
@vvalorous
vvalorous / README.md
Created September 29, 2018 02:43 — forked from sasha1sum/README.md
Cloudformation and code to create an AWS Lambda to start a jenkins job on github push (via SNS)

Github/Jenkins Hook with AWS Lambda

Setup

  • Run github_hook_cf.py to generate the cloudformation template (requires troposphere).
  • Run the cloudformation template in desired region
  • Once complete, take the values of the outputs and register in Github (Settings -> Webhooks & services -> Amazon SNS), this can be done on a repo or organization level
  • Add the created SNS topic to the generated lambdas event source1
  • Go to the Advanced Settings settings in the lambda configuration and add it to the VPC if needed.2
@vvalorous
vvalorous / lambda_function-ECS-cloudwatch-slack.py
Created September 29, 2018 02:42 — forked from dfetterman/lambda_function-ECS-cloudwatch-slack.py
Lambda function that takes ECS Cloudwatch events and sends a notification to Slack
# Written by Dane Fetterman on 12/1/2016
# https://aws.amazon.com/blogs/compute/monitor-cluster-state-with-amazon-ecs-event-stream/
# Where they use a cloud watch event from ECS to notify a SNS topic. We're
# sending a notification directly to slack instead
import requests
import json
from boto3 import session, client