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 only | |
# Can't use (EC2) SecurityGroups with Subnet | |
# Can't use (VPC) SecurityGroupIds with NetworkInterfaces | |
# Can't use SubnetId with NetworkInterfaces | |
def add_ec2(self): | |
name, tags = self._name_tags('ec2') | |
self.ec2 = self.t.add_resource( | |
ec2.Instance( | |
name, |
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
#!/usr/bin/env python | |
# An exponential backoff around Boto3 DynamoDB, whose own backoff eventually | |
# fails on long multipage scans. We'd like to use this as a wrapper somehow, | |
# see: https://gist.github.com/numberoverzero/cec21b8ca715401c5662 | |
from time import sleep | |
import boto3 | |
from boto3.dynamodb.conditions import Attr |
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 | |
# Returned 'cursor' can be of seemingly any length, and changes on each return | |
cs = boto3.client('cloudsearchdomain', | |
endpoint_url='https://search-thing-xxx.us-east-1.cloudsearch.amazonaws.com', | |
region_name='us-east-1') | |
size = 4 | |
cursor = 'initial' | |
while True: |
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 | |
# found is always the same | |
# start is the index into the total results, not a page of size results | |
cs = boto3.client('cloudsearchdomain', | |
endpoint_url='https://search-name-xxx.us-east-1.cloudsearch.amazonaws.com', | |
region_name='us-east-1') | |
size = 4 |
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
#!/usr/bin/env python3 | |
""" | |
We want to query of a page 'size' of N results and return them, and also a | |
'next' and 'previous' link. Those CloudSearch 'start' offsets are based on the | |
page (for our app, starting at 1) and the size. So with size=100: page=1 has | |
start=0, page=2 has start=100, page=10 has start=100. We don't want to return | |
'previous' if we're at page=1, and don't want to return 'next' if it's beyond | |
the maximum results 'found'. So if size=100 and found=543, the last page=5, | |
there is no page=6. More generally: lastpage = int(found / size). | |
""" |
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
# ... | |
[loggers] | |
keys = root, rival, sqlalchemy, boto3 | |
# ... | |
[logger_boto3] | |
# boto3.resources.action spews binary contents of file put_object at INFO, suppress | |
level = WARN | |
handlers = |
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
#!/usr/bin/env python3 | |
# Setup logs so our app shows INFO but boto shows at WARNING | |
import logging | |
import boto3 | |
# Don't show boto INFO; if we don't call this our own INFO logs aren't seen! | |
logging.basicConfig(level=logging.WARNING) | |
# Define our logger to show INFO logs |
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
#!/usr/bin/env python3 | |
# Get file path from sys.argv and upload as a presigned URL | |
import os | |
import sys | |
import boto3 | |
import requests | |
asset_path = sys.argv[1] | |
_, asset_fname = os.path.split(asset_path) |
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
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Description": "Apply policy to NEW bucket", | |
"Resources": { | |
"Queue": { | |
"Type": "AWS::SQS::Queue", | |
"Properties": { | |
"QueueName": "cshenton-tropo-queue" |
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
#!/usr/bin/env python | |
import sys | |
from wsgiref.simple_server import make_server | |
from pyramid.config import Configurator | |
from pyramid.response import Response | |
from pyramid.view import view_config | |
from pyramid.view import view_defaults |