Skip to content

Instantly share code, notes, and snippets.

View ankona's full-sized avatar
🏠
Working from home

Chris McBride ankona

🏠
Working from home
View GitHub Profile
@ankona
ankona / file_list_s3.py
Last active August 29, 2015 14:23
List all the files in an S3 bucket
AWS_ACCESS_KEY_ID = '' # todo: insert aws key.
AWS_ACCESS_KEY_SECRET = '' # todo: insert aws secret.
import os
import boto
import boto.s3
import os.path
import sys, getopt
import logging
@ankona
ankona / resize_virtualbox_vdi
Last active August 29, 2015 14:27
MAC resize command for VirtualBox .vdi
VBoxManage clonehd [OldHDDFile.vdi] [NewHDDFile.vdi] --existing - See more at: http://tips.kaali.co.uk/2012/03/16/expand-or-increase-the-size-of-virtual-box-vdi-dis/#sthash.WFNw5Rha.dpuf
@ankona
ankona / copy_properties.py
Created October 30, 2015 19:43
Copy properties from one python object to another
def __copy_properties(copy_from, copy_to):
for key in copy_from:
print 'found ' + str(key)
if hasattr(copy_to, key):
print 'for key "{2}" - copying value "{0}" from copy_from and replacing value "{1}" in copy_to'.format(copy_from[key], getattr(copy_to, key), key)
setattr(copy_to, key, copy_from[key])
@ankona
ankona / compare_uploads.cs
Last active November 18, 2015 23:06
Compare s3Client.putObject and TransferUtility.upload methods
using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using Amazon.Runtime;
using Amazon.S3;
using System.Configuration;
{
"AWSTemplateFormatVersion": "2010-09-09",
"Metadata": {
},
"Parameters": {
"EnvironmentParameter": {
"Type": "String",
"Default": "dev",
"AllowedValues": ["dev", "test", "stage", "lt", "prod"],
"Description": "Supply an environment from the choices: dev, test, stage, lt, or prod. The default is dev."
@ankona
ankona / get_api_id_from_stack.py
Created May 4, 2016 17:33
query a cloudformation stack for it's resources and find the first RestAPI id in it
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. module:: get_api_id_from_stack
:synopsis:
"""
import boto3
import sys
@ankona
ankona / deploy_cf_script.py
Created May 4, 2016 17:36
starter script to use boto / aws API to deploy a cloudformation script
import os
import time
import boto3
from botocore.exceptions import ClientError
def get_api_id_from_stack(stack_name):
api_id = ""
try:
cloudformation = boto3.client('cloudformation')
@ankona
ankona / templatize_swagger.py
Created May 4, 2016 17:41
script to alter a templatized swagger file so it can be pasted into a cloudformation script as a ::RestApi body value
import re
import json
p = re.compile("\{\{[\w]+\}\}")
input_path = '/path/to/swagger.json'
add_whitespace = False
f = open(input_path)
fw = open(input_path + '.notokens', 'w')
@ankona
ankona / settingsExample.py
Created May 23, 2016 18:25
settings table example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import boto3
from boto.dynamodb2.table import Table
def saveSetting(applicationName, settingName, value):
client = boto3.client('dynamodb')
response = client.update_item(TableName="chrisSettings",
Key={ "applicationName": { "S": applicationName } },
@ankona
ankona / assume-role-bash.sh
Created July 11, 2016 14:40
STS Assume Role (BASH)
role_result=$(aws sts assume-role --role-arn "%deployer_arn%" --role-session-name "deploy-dynamo-assets" --external-id "%assume_role_external_id%")
secret_key=$(echo $role_result | python -mjson.tool | grep "SecretAccessKey" | awk -F':' '{print $2}'| sed "s/[ |\"|,]//g")
session_token=$(echo $role_result | python -mjson.tool | grep "SessionToken" | awk -F':' '{print $2}'| sed "s/[ |\"|,]//g")
access_key=$(echo $role_result | python -mjson.tool | grep "AccessKeyId" | awk -F':' '{print $2}'| sed "s/[ |\"|,]//g")
echo "##teamcity[setParameter name='env.AWS_SECRET_ACCESS_KEY' value='${secret_key}']"
echo "##teamcity[setParameter name='env.AWS_SECURITY_TOKEN' value='${session_token}']"
echo "##teamcity[setParameter name='env.AWS_ACCESS_KEY_ID' value='${access_key}']"