OLD | NEW |
(Empty) | |
| 1 .. _sqs_tut: |
| 2 |
| 3 ======================================= |
| 4 An Introduction to boto's RDS interface |
| 5 ======================================= |
| 6 |
| 7 This tutorial focuses on the boto interface to the Relational Database Service |
| 8 from Amazon Web Services. This tutorial assumes that you have boto already |
| 9 downloaded and installed, and that you wish to setup a MySQL instance in RDS. |
| 10 |
| 11 Creating a Connection |
| 12 --------------------- |
| 13 The first step in accessing RDS is to create a connection to the service. |
| 14 The recommended method of doing this is as follows:: |
| 15 |
| 16 >>> import boto.rds |
| 17 >>> conn = boto.rds.connect_to_region( |
| 18 ... "us-east-1", |
| 19 ... aws_access_key_id='<aws access key'>, |
| 20 ... aws_secret_access_key='<aws secret key>') |
| 21 |
| 22 At this point the variable conn will point to an RDSConnection object in the |
| 23 US-EAST-1 region. Bear in mind that just as any other AWS service, RDS is |
| 24 region-specific. In this example, the AWS access key and AWS secret key are |
| 25 passed in to the method explicitely. Alternatively, you can set the environment |
| 26 variables: |
| 27 |
| 28 * ``AWS_ACCESS_KEY_ID`` - Your AWS Access Key ID |
| 29 * ``AWS_SECRET_ACCESS_KEY`` - Your AWS Secret Access Key |
| 30 |
| 31 and then simply call:: |
| 32 |
| 33 >>> import boto.rds |
| 34 >>> conn = boto.rds.connect_to_region("us-east-1") |
| 35 |
| 36 In either case, conn will point to an RDSConnection object which we will |
| 37 use throughout the remainder of this tutorial. |
| 38 |
| 39 Starting an RDS Instance |
| 40 ------------------------ |
| 41 |
| 42 Creating a DB instance is easy. You can do so as follows:: |
| 43 |
| 44 >>> db = conn.create_dbinstance("db-master-1", 10, 'db.m1.small', 'root', 'hu
nter2') |
| 45 |
| 46 This example would create a DB identified as ``db-master-1`` with 10GB of |
| 47 storage. This instance would be running on ``db.m1.small`` type, with the login |
| 48 name being ``root``, and the password ``hunter2``. |
| 49 |
| 50 To check on the status of your RDS instance, you will have to query the RDS conn
ection again:: |
| 51 |
| 52 >>> instances = conn.get_all_dbinstances("db-master-1") |
| 53 >>> instances |
| 54 [DBInstance:db-master-1] |
| 55 >>> db = instances[0] |
| 56 >>> db.status |
| 57 u'available' |
| 58 >>> db.endpoint |
| 59 (u'db-master-1.aaaaaaaaaa.us-east-1.rds.amazonaws.com', 3306) |
| 60 |
| 61 Creating a Security Group |
| 62 ------------------------- |
| 63 |
| 64 Before you can actually connect to this RDS service, you must first |
| 65 create a security group. You can add a CIDR range or an :py:class:`EC2 security |
| 66 group <boto.ec2.securitygroup.SecurityGroup>` to your :py:class:`DB security |
| 67 group <boto.rds.dbsecuritygroup.DBSecurityGroup>` :: |
| 68 |
| 69 >>> sg = conn.create_dbsecurity_group('web_servers', 'Web front-ends') |
| 70 >>> sg.authorize(cidr_ip='10.3.2.45/32') |
| 71 True |
| 72 |
| 73 You can then associate this security group with your RDS instance:: |
| 74 |
| 75 >>> db.modify(security_groups=[sg]) |
| 76 |
| 77 |
| 78 Connecting to your New Database |
| 79 ------------------------------- |
| 80 |
| 81 Once you have reached this step, you can connect to your RDS instance as you |
| 82 would with any other MySQL instance:: |
| 83 |
| 84 >>> db.endpoint |
| 85 (u'db-master-1.aaaaaaaaaa.us-east-1.rds.amazonaws.com', 3306) |
| 86 |
| 87 % mysql -h db-master-1.aaaaaaaaaa.us-east-1.rds.amazonaws.com -u root -phunt
er2 |
| 88 mysql> |
| 89 |
| 90 |
| 91 Making a backup |
| 92 --------------- |
| 93 |
| 94 You can also create snapshots of your database very easily:: |
| 95 |
| 96 >>> db.snapshot('db-master-1-2013-02-05') |
| 97 DBSnapshot:db-master-1-2013-02-05 |
| 98 |
| 99 |
| 100 Once this snapshot is complete, you can create a new database instance from |
| 101 it:: |
| 102 |
| 103 >>> db2 = conn.restore_dbinstance_from_dbsnapshot( |
| 104 ... 'db-master-1-2013-02-05', |
| 105 ... 'db-restored-1', |
| 106 ... 'db.m1.small', |
| 107 ... 'us-east-1') |
| 108 |
OLD | NEW |