This file contains 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
#! /user/bin/env python | |
from subprocess import check_cal | |
import urllib2 | |
import boto.ec2 | |
f = urllib2.urlopen('http://169.254.169.254/latest/meta-data/instance-id') | |
id = f.readline() | |
region = boto.ec2.get_region('us-west-2') |
This file contains 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 | |
# -*- coding: utf-8 -*- | |
import sqlite3 | |
if __name__ == "__main__": | |
con = sqlite3.connect("dbname.db") | |
con.row_factory = sqlite3.Row | |
for row in con.execute("select col1, col2 from table_name"): | |
print row['col1'], row['col2'] |
This file contains 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
#!/bin/env python | |
import boto.ec2 | |
region_info = [r for r in boto.ec2.regisons() if r.nmae == '<REGION-NAME>'][0] |
This file contains 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
#!/bin/env python | |
import boto | |
import boto.ec2 | |
regison = boto.ec2.get_region('us-east-1') | |
conn = boto.connect_cloudwatch(region=region) | |
conn.list_metrics() |
This file contains 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
#!/bin/env python | |
import boto.ec2.cloudwatch | |
region = [r for r in boto.ec2.cloudwatch.regions() if r.nmae == '<REGION-NAME>'][0] | |
conn = boto.connect_cloudwatch(region=region) | |
conn.list_metrics() |
This file contains 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
#!/bin/env python | |
from datetime import datetime, timedelta | |
end = datetime.now() | |
start = end - timedelta(hours=1) | |
data = conn.get_metric_statistics(60, start, end, "CPUUtilization","AWS/RDS","Average", { 'DBInstanceIdentifier' : 'activity' }, 'Percent') |
This file contains 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
# -*- coding: utf-8 -*- | |
import signal | |
import boto.sns | |
def timeout(limit, topic, subject='Execution Timeout.', body='Please check program.', region='us-east-1'): | |
''' | |
指定した実行時間(秒)に終了しなかった場合、awsのsnsで通知するデコレータです。 | |
この例では long_time_func()を呼び出し後10秒経過していたら aws snsに通知が飛びます。 | |
@timeout(limit=10,topic='arn:aws:sns:xxxxxxxx:yyyyyyy') | |
def long_time_func(): |
This file contains 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
# -*- coding: utf-8 -*- | |
import signal | |
import boto.sns | |
def timeout(limit, topic, subject='Execution Timeout.', body='Please check program.', region='us-east-1'): | |
''' | |
使い方:指定した実行時間に終了しなかった場合、awsのsnsで通知するデコレータです。 | |
@timeout(limit=3600, topic='arn:aws:sns:xxxxxxxx:yyyyyyy') | |
def long_time_function(): | |
very_very_long_calc() |
This file contains 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
role(:server) do | |
hosts = Array.new | |
db = SQLite3::Database.new("serverlist.db") | |
db.execute("SELECT name FROM serverlist WHERE role = 'server'") do |host| | |
hosts.push(host[0]) | |
end | |
db.close() | |
hosts | |
end |
This file contains 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 boto | |
import boto.ec2 | |
import boto.vpc | |
region = boto.ec2.get_region('REGION_NAME') | |
c = boto.connect_vpc(region=region) | |
subnets = c.get_all_subnets() |
OlderNewer