Created
March 6, 2012 04:13
-
-
Save yyuu/1983382 to your computer and use it in GitHub Desktop.
boto REPL
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 boto.ec2 | |
| import boto.ec2.autoscale | |
| import boto.route53 | |
| import boto.s3.connection | |
| import boto.sqs | |
| import code | |
| import optparse | |
| import os | |
| import sys | |
| try: | |
| import readline | |
| except ImportError: | |
| pass | |
| class attr_dict(dict): | |
| def __getattr__(self, key): | |
| return self.__getitem__(key) | |
| def __setattr__(self, key, val): | |
| return self.__setitem__(key, val) | |
| def connect(region, access_key_id, secret_key): | |
| aws = attr_dict() | |
| aws.autoscaling = boto.ec2.autoscale.connect_to_region(region, aws_access_key_id=access_key_id, aws_secret_access_key=secret_key) | |
| aws.ec2 = boto.ec2.connect_to_region(region, aws_access_key_id=access_key_id, aws_secret_access_key=secret_key) | |
| aws.route53 = boto.route53.Route53Connection(aws_access_key_id=access_key_id, aws_secret_access_key=secret_key) | |
| aws.sqs = boto.sqs.connect_to_region(region, aws_access_key_id=access_key_id, aws_secret_access_key=secret_key) | |
| aws.s3 = boto.s3.connection.S3Connection(aws_access_key_id=access_key_id, aws_secret_access_key=secret_key) | |
| return aws | |
| def main(args): | |
| _parser = optparse.OptionParser("usage %prog [OPTIONS]") | |
| _parser.add_option('--region', type='string', dest='region', help='region name to connect to', default=os.getenv('EC2_REGION')) | |
| _parser.add_option('-I', '--access-key-id', type='string', dest='access_key_id', help='AWS Access Id to use', default=os.getenv('AWS_ACCESS_KEY_ID')) | |
| _parser.add_option('-S', '--secret-key', type='string', dest='secret_key', help='AWS Secret Key to use', default=os.getenv('AWS_SECRET_ACCESS_KEY')) | |
| _options, args = _parser.parse_args(args) | |
| aws = connect(_options.region, _options.access_key_id, _options.secret_key) | |
| code.InteractiveConsole(locals=locals()).interact() | |
| if __name__ == '__main__': | |
| main(sys.argv) | |
| # vim:set ft=python : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment