Skip to content

Instantly share code, notes, and snippets.

@vvalorous
vvalorous / sns-to-slack.py
Created September 4, 2018 22:30 — forked from hayd/sns-to-slack.py
sns to slack aws lambda python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Follow these steps to configure the webhook in Slack:
1. Navigate to https://<your-team-domain>.slack.com/services/new
2. Search for and select "Incoming WebHooks".
@vvalorous
vvalorous / gist:1a20c63d06250034e210bc74ecbcccc9
Created September 1, 2018 06:49 — forked from bkruger99/gist:6bbaacf1e7fa49891d421d6a1a7ba9c9
aws connection helper for python. Allows you to use a single call to get either a client or resource and also has sts support built in. If you use this, I'd appreciate feedback.
#!/usr/bin/env python
import boto3
"""
Generic AWS Helper call class to setup a boto3 Session. Now with assume role support.
Pass in 'type=' to do either 'client' or 'resource'
usage:
@vvalorous
vvalorous / AddAllOrgAccountsToPolicy.py
Created August 28, 2018 03:58 — forked from tom-butler/AddAllOrgAccountsToPolicy.py
Boto3: Add All Org Accounts To IAM Policy
#!/usr/bin/env python3
import boto3
import json
central_logging = '<insert your central logging account id here>'
# Variables for the grafana monitoring server
role_name = 'monitoring_prodcloudwatch_access_role'
policy_arn = 'arn:aws:iam::<insert your central logging account id here>:policy/monitor-assumerole'
@vvalorous
vvalorous / gist:3cde85f6ed585506ba338d6c335a61d3
Created August 28, 2018 03:57 — forked from xxxVxxx/gist:9648264fd6f41bbb1f65
boto3 aws find all IAM accesskeys details for the account
import boto3
boto3.setup_default_session(profile_name='IAM')
resource = boto3.resource('iam')
client = boto3.client("iam")
KEY = 'LastUsedDate'
for user in resource.users.all():
@vvalorous
vvalorous / eventbrite_to_slack.py
Created July 1, 2018 01:57 — forked from simonw/eventbrite_to_slack.py
Send new eventbrite orders to a Slack channel (Django view function)
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
import requests, json
# Get an OAuth token from https://www.eventbrite.com/myaccount/apps/
# Create a new app, then expand the expandy-thingy and copy out the
# 'Your personal OAuth token' value.
EVENTBRITE_OAUTH_TOKEN = '...'
# Should look something like https://yoursite.slack.com/services/hooks/incoming-webhook?token=xxx...xxx
@vvalorous
vvalorous / django-basic-slack-OAuth.py
Created July 1, 2018 01:57 — forked from wilhelmklopp/django-basic-slack-OAuth.py
Example of how do to a basic Slack OAuth implementation in Django
# urls.py
from django.conf.urls import url
from main import views
urlpatterns = [
url(r'^oauthcallback/', views.oauthcallback)
]
# models.py
from django.db import models
@vvalorous
vvalorous / awslambda.bootstrap.py
Created June 22, 2018 23:06 — forked from lucasrcosta/awslambda.bootstrap.py
AWS Lambda Python Runtime
# -*- coding: utf-8 -*-
# /var/runtime/awslambda/bootstrap.py
"""
aws_lambda.bootstrap.py
Amazon Lambda
Copyright (c) 2013 Amazon. All rights reserved.
Lambda runtime implemention
"""
@vvalorous
vvalorous / idling.py
Created June 21, 2018 17:42 — forked from chiradeep/idling.py
boto script to find and stop idle instances
import argparse
import boto3
import datetime
from dateutil.tz import tzutc
def is_in_autoscale_group(region, instance_id):
asg = boto3.client('autoscaling', region_name=region)
instances = \
asg.describe_auto_scaling_instances(InstanceIds=[instance_id])
@vvalorous
vvalorous / valet.py
Created June 21, 2018 17:41 — forked from jcharlesworth/valet.py
Control AWS instance uptime via tags with crontab scheduling
# Copyright (C) 2014 Cloudablity
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@vvalorous
vvalorous / SlackRTM.py
Created June 20, 2018 18:44 — forked from Terrance/SlackRTM.py
A minimal asyncio client for the Slack real-time messaging (RTM) APIs.
import aiohttp
import asyncio
import logging
class SlackAPIError(Exception): pass
class Slack(object):
"""